2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 // Leonardo Zide (leo@lokigames.com)
30 #include "debugging/debugging.h"
37 #include "ifilesystem.h"
40 #include "gtkutil/messagebox.h"
42 #include <gtk/gtklabel.h>
43 #include <gtk/gtkmenuitem.h>
45 #include "generic/callback.h"
46 #include "string/string.h"
47 #include "stream/stringstream.h"
50 #include "eclasslib.h"
52 #include "moduleobserver.h"
54 #include "gtkutil/menu.h"
55 #include "gtkutil/container.h"
56 #include "gtkutil/widget.h"
57 #include "gtkutil/glwidget.h"
58 #include "gtkutil/filechooser.h"
62 #include "brushmanip.h"
63 #include "selection.h"
65 #include "camwindow.h"
66 #include "texwindow.h"
67 #include "mainframe.h"
68 #include "preferences.h"
72 #include "windowobservers.h"
74 void LoadTextureRGBA( qtexture_t* q, unsigned char* pPixels, int nWidth, int nHeight );
77 extern bool g_brush_always_caulk;
83 Vector3 m_ptClip; // the 3d point
90 m_ptClip[0] = m_ptClip[1] = m_ptClip[2] = 0.0;
104 /*! Draw clip/path point with rasterized number label */
105 void Draw( int num, float scale );
106 /*! Draw clip/path point with rasterized string label */
107 void Draw( const char *label, float scale );
110 VIEWTYPE g_clip_viewtype;
111 bool g_bSwitch = true;
112 bool g_clip_useCaulk = false;
113 bool g_quick_clipper = false;
117 ClipPoint* g_pMovingClip = 0;
119 /* Drawing clip points */
120 void ClipPoint::Draw( int num, float scale ){
121 StringOutputStream label( 4 );
123 Draw( label.c_str(), scale );
126 void ClipPoint::Draw( const char *label, float scale ){
129 glColor3fv( vector3_to_array( g_xywindow_globals.color_clipper ) );
130 glBegin( GL_POINTS );
131 glVertex3fv( vector3_to_array( m_ptClip ) );
135 float offset = 2.0f / scale;
138 glRasterPos3f( m_ptClip[0] + offset, m_ptClip[1] + offset, m_ptClip[2] + offset );
139 glCallLists( GLsizei( strlen( label ) ), GL_UNSIGNED_BYTE, label );
142 float fDiff( float f1, float f2 ){
151 inline double ClipPoint_Intersect( const ClipPoint& clip, const Vector3& point, VIEWTYPE viewtype, float scale ){
152 int nDim1 = ( viewtype == YZ ) ? 1 : 0;
153 int nDim2 = ( viewtype == XY ) ? 1 : 2;
154 double screenDistanceSquared( vector2_length_squared( Vector2( fDiff( clip.m_ptClip[nDim1], point[nDim1] ) * scale, fDiff( clip.m_ptClip[nDim2], point[nDim2] ) * scale ) ) );
155 if ( screenDistanceSquared < 8 * 8 ) {
156 return screenDistanceSquared;
161 inline void ClipPoint_testSelect( ClipPoint& clip, const Vector3& point, VIEWTYPE viewtype, float scale, double& bestDistance, ClipPoint*& bestClip ){
163 double distance = ClipPoint_Intersect( clip, point, viewtype, scale );
164 if ( distance < bestDistance ) {
165 bestDistance = distance;
171 inline ClipPoint* GlobalClipPoints_Find( const Vector3& point, VIEWTYPE viewtype, float scale ){
172 double bestDistance = FLT_MAX;
173 ClipPoint* bestClip = 0;
174 ClipPoint_testSelect( g_Clip1, point, viewtype, scale, bestDistance, bestClip );
175 ClipPoint_testSelect( g_Clip2, point, viewtype, scale, bestDistance, bestClip );
176 ClipPoint_testSelect( g_Clip3, point, viewtype, scale, bestDistance, bestClip );
180 inline void GlobalClipPoints_Draw( float scale ){
182 if ( g_Clip1.Set() ) {
183 g_Clip1.Draw( 1, scale );
185 if ( g_Clip2.Set() ) {
186 g_Clip2.Draw( 2, scale );
188 if ( g_Clip3.Set() ) {
189 g_Clip3.Draw( 3, scale );
193 inline bool GlobalClipPoints_valid(){
194 return g_Clip1.Set() && g_Clip2.Set();
197 void PlanePointsFromClipPoints( Vector3 planepts[3], const AABB& bounds, int viewtype ){
198 ASSERT_MESSAGE( GlobalClipPoints_valid(), "clipper points not initialised" );
199 planepts[0] = g_Clip1.m_ptClip;
200 planepts[1] = g_Clip2.m_ptClip;
201 planepts[2] = g_Clip3.m_ptClip;
202 Vector3 maxs( vector3_added( bounds.origin, bounds.extents ) );
203 Vector3 mins( vector3_subtracted( bounds.origin, bounds.extents ) );
204 if ( !g_Clip3.Set() ) {
205 int n = ( viewtype == XY ) ? 2 : ( viewtype == YZ ) ? 0 : 1;
206 int x = ( n == 0 ) ? 1 : 0;
207 int y = ( n == 2 ) ? 1 : 2;
209 if ( n == 1 ) { // on viewtype XZ, flip clip points
210 planepts[0][n] = maxs[n];
211 planepts[1][n] = maxs[n];
212 planepts[2][x] = g_Clip1.m_ptClip[x];
213 planepts[2][y] = g_Clip1.m_ptClip[y];
214 planepts[2][n] = mins[n];
218 planepts[0][n] = mins[n];
219 planepts[1][n] = mins[n];
220 planepts[2][x] = g_Clip1.m_ptClip[x];
221 planepts[2][y] = g_Clip1.m_ptClip[y];
222 planepts[2][n] = maxs[n];
229 if ( !GlobalClipPoints_valid() ) {
230 planepts[0] = Vector3( 0, 0, 0 );
231 planepts[1] = Vector3( 0, 0, 0 );
232 planepts[2] = Vector3( 0, 0, 0 );
233 Scene_BrushSetClipPlane( GlobalSceneGraph(), Plane3( 0, 0, 0, 0 ) );
237 AABB bounds( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) );
238 PlanePointsFromClipPoints( planepts, bounds, g_clip_viewtype );
240 std::swap( planepts[0], planepts[1] );
242 Scene_BrushSetClipPlane( GlobalSceneGraph(), plane3_for_points( planepts[0], planepts[1], planepts[2] ) );
244 ClipperChangeNotify();
247 const char* Clip_getShader(){
248 return g_clip_useCaulk ? "textures/common/caulk" : TextureBrowser_GetSelectedShader( GlobalTextureBrowser() );
252 if ( ClipMode() && GlobalClipPoints_valid() ) {
254 AABB bounds( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) );
255 PlanePointsFromClipPoints( planepts, bounds, g_clip_viewtype );
256 Scene_BrushSplitByPlane( GlobalSceneGraph(), planepts[0], planepts[1], planepts[2], Clip_getShader(), ( !g_bSwitch ) ? eFront : eBack );
261 ClipperChangeNotify();
262 if( g_quick_clipper ){
263 g_quick_clipper = false;
270 if ( ClipMode() && GlobalClipPoints_valid() ) {
272 AABB bounds( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) );
273 PlanePointsFromClipPoints( planepts, bounds, g_clip_viewtype );
274 Scene_BrushSplitByPlane( GlobalSceneGraph(), planepts[0], planepts[1], planepts[2], Clip_getShader(), eFrontAndBack );
279 ClipperChangeNotify();
280 if( g_quick_clipper ){
281 g_quick_clipper = false;
288 g_bSwitch = !g_bSwitch;
290 ClipperChangeNotify();
293 void OnClipMode( bool enabled ){
298 if ( !enabled && g_pMovingClip ) {
303 ClipperChangeNotify();
307 return GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eClip;
310 void NewClipPoint( const Vector3& point ){
311 if ( g_Clip1.Set() == false ) {
312 g_Clip1.m_ptClip = point;
315 else if ( g_Clip2.Set() == false ) {
316 g_Clip2.m_ptClip = point;
319 else if ( g_Clip3.Set() == false ) {
320 g_Clip3.m_ptClip = point;
328 g_Clip1.m_ptClip = point;
333 ClipperChangeNotify();
338 struct xywindow_globals_private_t
342 // these are in the View > Show menu with Show coordinates
344 bool show_coordinates;
358 xywindow_globals_private_t() :
362 show_coordinates( true ),
364 show_outline( false ),
367 d_show_work( false ),
369 show_blocks( false ),
371 m_bCamXYUpdate( true ),
372 m_bChaseMouse( true ),
373 m_bSizePaint( true ){
378 xywindow_globals_t g_xywindow_globals;
379 xywindow_globals_private_t g_xywindow_globals_private;
381 const unsigned int RAD_NONE = 0x00;
382 const unsigned int RAD_SHIFT = 0x01;
383 const unsigned int RAD_ALT = 0x02;
384 const unsigned int RAD_CONTROL = 0x04;
385 const unsigned int RAD_PRESS = 0x08;
386 const unsigned int RAD_LBUTTON = 0x10;
387 const unsigned int RAD_MBUTTON = 0x20;
388 const unsigned int RAD_RBUTTON = 0x40;
390 inline ButtonIdentifier button_for_flags( unsigned int flags ){
391 if ( flags & RAD_LBUTTON ) {
394 if ( flags & RAD_RBUTTON ) {
395 return c_buttonRight;
397 if ( flags & RAD_MBUTTON ) {
398 return c_buttonMiddle;
400 return c_buttonInvalid;
403 inline ModifierFlags modifiers_for_flags( unsigned int flags ){
404 ModifierFlags modifiers = c_modifierNone;
405 if ( flags & RAD_SHIFT ) {
406 modifiers |= c_modifierShift;
408 if ( flags & RAD_CONTROL ) {
409 modifiers |= c_modifierControl;
411 if ( flags & RAD_ALT ) {
412 modifiers |= c_modifierAlt;
417 inline unsigned int buttons_for_button_and_modifiers( ButtonIdentifier button, ModifierFlags flags ){
418 unsigned int buttons = 0;
420 switch ( button.get() )
422 case ButtonEnumeration::LEFT: buttons |= RAD_LBUTTON; break;
423 case ButtonEnumeration::MIDDLE: buttons |= RAD_MBUTTON; break;
424 case ButtonEnumeration::RIGHT: buttons |= RAD_RBUTTON; break;
427 if ( bitfield_enabled( flags, c_modifierControl ) ) {
428 buttons |= RAD_CONTROL;
431 if ( bitfield_enabled( flags, c_modifierShift ) ) {
432 buttons |= RAD_SHIFT;
435 if ( bitfield_enabled( flags, c_modifierAlt ) ) {
442 inline unsigned int buttons_for_event_button( GdkEventButton* event ){
443 unsigned int flags = 0;
445 switch ( event->button )
447 case 1: flags |= RAD_LBUTTON; break;
448 case 2: flags |= RAD_MBUTTON; break;
449 case 3: flags |= RAD_RBUTTON; break;
452 if ( ( event->state & GDK_CONTROL_MASK ) != 0 ) {
453 flags |= RAD_CONTROL;
456 if ( ( event->state & GDK_SHIFT_MASK ) != 0 ) {
460 if ( ( event->state & GDK_MOD1_MASK ) != 0 ) {
467 inline unsigned int buttons_for_state( guint state ){
468 unsigned int flags = 0;
470 if ( ( state & GDK_BUTTON1_MASK ) != 0 ) {
471 flags |= RAD_LBUTTON;
474 if ( ( state & GDK_BUTTON2_MASK ) != 0 ) {
475 flags |= RAD_MBUTTON;
478 if ( ( state & GDK_BUTTON3_MASK ) != 0 ) {
479 flags |= RAD_RBUTTON;
482 if ( ( state & GDK_CONTROL_MASK ) != 0 ) {
483 flags |= RAD_CONTROL;
486 if ( ( state & GDK_SHIFT_MASK ) != 0 ) {
490 if ( ( state & GDK_MOD1_MASK ) != 0 ) {
498 void XYWnd::SetScale( float f ){
502 XYWnd_Update( *this );
505 void XYWnd::ZoomIn(){
506 float max_scale = 64;
507 float scale = Scale() * 5.0f / 4.0f;
508 if ( scale > max_scale ) {
509 if ( Scale() != max_scale ) {
510 SetScale( max_scale );
520 // NOTE: the zoom out factor is 4/5, we could think about customizing it
521 // we don't go below a zoom factor corresponding to 10% of the max world size
522 // (this has to be computed against the window size)
523 void XYWnd::ZoomOut(){
524 float min_scale = MIN( Width(), Height() ) / ( 1.1f * ( g_MaxWorldCoord - g_MinWorldCoord ) );
525 float scale = Scale() * 4.0f / 5.0f;
526 if ( scale < min_scale ) {
527 if ( Scale() != min_scale ) {
528 SetScale( min_scale );
537 void XYWnd::ZoomInWithMouse( int pointx, int pointy ){
538 float old_scale = Scale();
540 if ( g_xywindow_globals.m_bImprovedWheelZoom ) {
541 float scale_diff = 1.0 / old_scale - 1.0 / Scale();
542 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
543 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
544 Vector3 origin = GetOrigin();
545 origin[nDim1] += scale_diff * (pointx - 0.5 * Width());
546 origin[nDim2] -= scale_diff * (pointy - 0.5 * Height());
551 VIEWTYPE GlobalXYWnd_getCurrentViewType(){
552 ASSERT_NOTNULL( g_pParentWnd );
553 ASSERT_NOTNULL( g_pParentWnd->ActiveXY() );
554 return g_pParentWnd->ActiveXY()->GetViewType();
557 // =============================================================================
560 bool g_bCrossHairs = false;
562 GtkMenu* XYWnd::m_mnuDrop = 0;
564 // this is disabled, and broken
565 // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=394
569 width = g_pParentWnd->ActiveXY()->Width();
570 height = g_pParentWnd->ActiveXY()->Height();
572 const char* filename;
574 filename = file_dialog( GTK_WIDGET( MainFrame_getWindow() ), FALSE, "Save Image", 0, FILTER_BMP );
579 g_pParentWnd->ActiveXY()->MakeCurrent();
580 img = (unsigned char*)malloc( width * height * 3 );
581 glReadPixels( 0,0,width,height,GL_RGB,GL_UNSIGNED_BYTE,img );
584 fp = fopen( filename, "wb" );
587 unsigned long cmap, bfSize;
591 bfSize = 54 + width * height * 3;
593 long byteswritten = 0;
594 long pixoff = 54 + cmap * 4;
596 char m1 = 'B', m2 = 'M';
597 fwrite( &m1, 1, 1, fp ); byteswritten++; // B
598 fwrite( &m2, 1, 1, fp ); byteswritten++; // M
599 fwrite( &bfSize, 4, 1, fp ); byteswritten += 4; // bfSize
600 fwrite( &res, 2, 1, fp ); byteswritten += 2; // bfReserved1
601 fwrite( &res, 2, 1, fp ); byteswritten += 2; // bfReserved2
602 fwrite( &pixoff, 4, 1, fp ); byteswritten += 4; // bfOffBits
604 unsigned long biSize = 40, compress = 0, size = 0;
606 unsigned short planes = 1;
607 fwrite( &biSize, 4, 1, fp ); byteswritten += 4; // biSize
608 fwrite( &width, 4, 1, fp ); byteswritten += 4; // biWidth
609 fwrite( &height, 4, 1, fp ); byteswritten += 4; // biHeight
610 fwrite( &planes, 2, 1, fp ); byteswritten += 2; // biPlanes
611 fwrite( &bits, 2, 1, fp ); byteswritten += 2; // biBitCount
612 fwrite( &compress, 4, 1, fp ); byteswritten += 4; // biCompression
613 fwrite( &size, 4, 1, fp ); byteswritten += 4; // biSizeImage
614 fwrite( &pixels, 4, 1, fp ); byteswritten += 4; // biXPelsPerMeter
615 fwrite( &pixels, 4, 1, fp ); byteswritten += 4; // biYPelsPerMeter
616 fwrite( &cmap, 4, 1, fp ); byteswritten += 4; // biClrUsed
617 fwrite( &cmap, 4, 1, fp ); byteswritten += 4; // biClrImportant
619 unsigned long widthDW = ( ( ( width * 24 ) + 31 ) / 32 * 4 );
620 long row, row_size = width * 3;
621 for ( row = 0; row < height; row++ )
623 unsigned char* buf = img + row * row_size;
627 for ( col = 0; col < row_size; col += 3 )
629 putc( buf[col + 2], fp );
630 putc( buf[col + 1], fp );
631 putc( buf[col], fp );
633 byteswritten += row_size;
636 for ( count = row_size; count < widthDW; count++ )
638 putc( 0, fp ); // dummy
653 Timer g_chasemouse_timer;
655 void XYWnd::ChaseMouse(){
656 float multiplier = g_chasemouse_timer.elapsed_msec() / 10.0f;
657 Scroll( float_to_integer( multiplier * m_chasemouse_delta_x ), float_to_integer( multiplier * -m_chasemouse_delta_y ) );
659 //globalOutputStream() << "chasemouse: multiplier=" << multiplier << " x=" << m_chasemouse_delta_x << " y=" << m_chasemouse_delta_y << '\n';
661 XY_MouseMoved( m_chasemouse_current_x, m_chasemouse_current_y, getButtonState() );
662 g_chasemouse_timer.start();
665 gboolean xywnd_chasemouse( gpointer data ){
666 reinterpret_cast<XYWnd*>( data )->ChaseMouse();
670 inline const int& min_int( const int& left, const int& right ){
671 return std::min( left, right );
674 bool XYWnd::chaseMouseMotion( int pointx, int pointy ){
675 m_chasemouse_delta_x = 0;
676 m_chasemouse_delta_y = 0;
678 if ( g_xywindow_globals_private.m_bChaseMouse && getButtonState() == RAD_LBUTTON ) {
679 const int epsilon = 16;
681 if ( pointx < epsilon ) {
682 m_chasemouse_delta_x = std::max( pointx, 0 ) - epsilon;
684 else if ( ( pointx - m_nWidth ) > -epsilon ) {
685 m_chasemouse_delta_x = min_int( ( pointx - m_nWidth ), 0 ) + epsilon;
688 if ( pointy < epsilon ) {
689 m_chasemouse_delta_y = std::max( pointy, 0 ) - epsilon;
691 else if ( ( pointy - m_nHeight ) > -epsilon ) {
692 m_chasemouse_delta_y = min_int( ( pointy - m_nHeight ), 0 ) + epsilon;
695 if ( m_chasemouse_delta_y != 0 || m_chasemouse_delta_x != 0 ) {
696 //globalOutputStream() << "chasemouse motion: x=" << pointx << " y=" << pointy << "... ";
697 m_chasemouse_current_x = pointx;
698 m_chasemouse_current_y = pointy;
699 if ( m_chasemouse_handler == 0 ) {
700 //globalOutputStream() << "chasemouse timer start... ";
701 g_chasemouse_timer.start();
702 m_chasemouse_handler = g_idle_add( xywnd_chasemouse, this );
708 if ( m_chasemouse_handler != 0 ) {
709 //globalOutputStream() << "chasemouse cancel\n";
710 g_source_remove( m_chasemouse_handler );
711 m_chasemouse_handler = 0;
717 if ( m_chasemouse_handler != 0 ) {
718 //globalOutputStream() << "chasemouse cancel\n";
719 g_source_remove( m_chasemouse_handler );
720 m_chasemouse_handler = 0;
726 // =============================================================================
728 Shader* XYWnd::m_state_selected = 0;
730 void xy_update_xor_rectangle( XYWnd& self, rect_t area ){
731 if ( GTK_WIDGET_VISIBLE( self.GetWidget() ) ) {
732 rectangle_t rect = rectangle_from_area( area.min, area.max, self.Width(), self.Height() );
733 int nDim1 = ( self.GetViewType() == YZ ) ? 1 : 0;
734 int nDim2 = ( self.GetViewType() == XY ) ? 1 : 2;
735 rect.x /= self.Scale();
736 rect.y /= self.Scale();
737 rect.w /= self.Scale();
738 rect.h /= self.Scale();
739 rect.x += self.GetOrigin()[nDim1];
740 rect.y += self.GetOrigin()[nDim2];
741 self.m_XORRectangle.set( rect );
745 gboolean xywnd_button_press( GtkWidget* widget, GdkEventButton* event, XYWnd* xywnd ){
746 if ( event->type == GDK_BUTTON_PRESS ) {
747 g_pParentWnd->SetActiveXY( xywnd );
749 xywnd->ButtonState_onMouseDown( buttons_for_event_button( event ) );
751 xywnd->onMouseDown( WindowVector( event->x, event->y ), button_for_button( event->button ), modifiers_for_state( event->state ) );
756 gboolean xywnd_button_release( GtkWidget* widget, GdkEventButton* event, XYWnd* xywnd ){
757 if ( event->type == GDK_BUTTON_RELEASE ) {
758 xywnd->XY_MouseUp( static_cast<int>( event->x ), static_cast<int>( event->y ), buttons_for_event_button( event ) );
760 xywnd->ButtonState_onMouseUp( buttons_for_event_button( event ) );
765 gboolean xywnd_focus_in( GtkWidget* widget, GdkEventFocus* event, XYWnd* xywnd ){
766 if ( event->type == GDK_FOCUS_CHANGE ) {
768 g_pParentWnd->SetActiveXY( xywnd );
774 void xywnd_motion( gdouble x, gdouble y, guint state, void* data ){
775 if ( reinterpret_cast<XYWnd*>( data )->chaseMouseMotion( static_cast<int>( x ), static_cast<int>( y ) ) ) {
778 reinterpret_cast<XYWnd*>( data )->XY_MouseMoved( static_cast<int>( x ), static_cast<int>( y ), buttons_for_state( state ) );
781 gboolean xywnd_wheel_scroll( GtkWidget* widget, GdkEventScroll* event, XYWnd* xywnd ){
782 if ( event->direction == GDK_SCROLL_UP ) {
783 xywnd->ZoomInWithMouse( (int)event->x, (int)event->y );
785 else if ( event->direction == GDK_SCROLL_DOWN ) {
791 gboolean xywnd_size_allocate( GtkWidget* widget, GtkAllocation* allocation, XYWnd* xywnd ){
792 xywnd->m_nWidth = allocation->width;
793 xywnd->m_nHeight = allocation->height;
794 xywnd->updateProjection();
795 xywnd->m_window_observer->onSizeChanged( xywnd->Width(), xywnd->Height() );
799 gboolean xywnd_expose( GtkWidget* widget, GdkEventExpose* event, XYWnd* xywnd ){
800 if ( glwidget_make_current( xywnd->GetWidget() ) != FALSE ) {
801 if ( Map_Valid( g_map ) && ScreenUpdates_Enabled() ) {
802 GlobalOpenGL_debugAssertNoErrors();
804 GlobalOpenGL_debugAssertNoErrors();
806 xywnd->m_XORRectangle.set( rectangle_t() );
808 glwidget_swap_buffers( xywnd->GetWidget() );
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 ),
825 m_window_observer( NewWindowObserver() ),
826 m_XORRectangle( m_gl_widget ),
827 m_chasemouse_handler( 0 ){
831 m_bNewBrushDrag = false;
832 m_move_started = false;
833 m_zoom_started = false;
844 m_backgroundActivated = false;
851 m_entityCreate = false;
855 GlobalWindowObservers_add( m_window_observer );
856 GlobalWindowObservers_connectWidget( m_gl_widget );
858 m_window_observer->setRectangleDrawCallback( ReferenceCaller1<XYWnd, rect_t, xy_update_xor_rectangle>( *this ) );
859 m_window_observer->setView( m_view );
861 gtk_widget_ref( m_gl_widget );
863 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 );
864 GTK_WIDGET_SET_FLAGS( m_gl_widget, GTK_CAN_FOCUS );
866 m_sizeHandler = g_signal_connect( G_OBJECT( m_gl_widget ), "size_allocate", G_CALLBACK( xywnd_size_allocate ), this );
867 m_exposeHandler = g_signal_connect( G_OBJECT( m_gl_widget ), "expose_event", G_CALLBACK( xywnd_expose ), this );
869 g_signal_connect( G_OBJECT( m_gl_widget ), "button_press_event", G_CALLBACK( xywnd_button_press ), this );
870 g_signal_connect( G_OBJECT( m_gl_widget ), "button_release_event", G_CALLBACK( xywnd_button_release ), this );
871 g_signal_connect( G_OBJECT( m_gl_widget ), "focus_in_event", G_CALLBACK( xywnd_focus_in ), this );
872 g_signal_connect( G_OBJECT( m_gl_widget ), "motion_notify_event", G_CALLBACK( DeferredMotion::gtk_motion ), &m_deferred_motion );
874 g_signal_connect( G_OBJECT( m_gl_widget ), "scroll_event", G_CALLBACK( xywnd_wheel_scroll ), this );
876 Map_addValidCallback( g_map, DeferredDrawOnMapValidChangedCaller( m_deferredDraw ) );
881 AddSceneChangeCallback( ReferenceCaller<XYWnd, &XYWnd_Update>( *this ) );
882 AddCameraMovedCallback( ReferenceCaller<XYWnd, &XYWnd_CameraMoved>( *this ) );
884 PressedButtons_connect( g_pressedButtons, m_gl_widget );
886 onMouseDown.connectLast( makeSignalHandler3( MouseDownCaller(), *this ) );
892 if ( m_mnuDrop != 0 ) {
893 gtk_widget_destroy( GTK_WIDGET( m_mnuDrop ) );
897 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_sizeHandler );
898 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_exposeHandler );
900 gtk_widget_unref( m_gl_widget );
902 m_window_observer->release();
905 void XYWnd::captureStates(){
906 m_state_selected = GlobalShaderCache().capture( "$XY_OVERLAY" );
909 void XYWnd::releaseStates(){
910 GlobalShaderCache().release( "$XY_OVERLAY" );
913 const Vector3& XYWnd::GetOrigin(){
917 void XYWnd::SetOrigin( const Vector3& origin ){
922 void XYWnd::Scroll( int x, int y ){
923 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
924 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
925 m_vOrigin[nDim1] += x / m_fScale;
926 m_vOrigin[nDim2] += y / m_fScale;
931 unsigned int Clipper_buttons(){
935 unsigned int Clipper_quick_buttons(){
936 return RAD_RBUTTON | RAD_CONTROL;
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 ) {
982 cursor = gdk_cursor_new( GDK_CROSSHAIR );
983 gdk_window_set_cursor( m_gl_widget->window, cursor );
984 gdk_cursor_unref( cursor );
988 gdk_window_set_cursor( m_gl_widget->window, 0 );
992 unsigned int MoveCamera_buttons(){
993 return RAD_CONTROL | ( g_glwindow_globals.m_nMouseType == ETwoButton ? RAD_RBUTTON : RAD_MBUTTON );
996 void XYWnd_PositionCamera( XYWnd* xywnd, int x, int y, CamWnd& camwnd ){
997 Vector3 origin( Camera_getOrigin( camwnd ) );
998 xywnd->XY_ToPoint( x, y, origin );
999 xywnd->XY_SnapToGrid( origin );
1000 Camera_setOrigin( camwnd, origin );
1003 unsigned int OrientCamera_buttons(){
1004 if ( g_glwindow_globals.m_nMouseType == ETwoButton ) {
1005 return RAD_RBUTTON | RAD_SHIFT | RAD_CONTROL;
1010 void XYWnd_OrientCamera( XYWnd* xywnd, int x, int y, CamWnd& camwnd ){
1011 Vector3 point = g_vector3_identity;
1012 xywnd->XY_ToPoint( x, y, point );
1013 xywnd->XY_SnapToGrid( point );
1014 vector3_subtract( point, Camera_getOrigin( camwnd ) );
1016 int n1 = ( xywnd->GetViewType() == XY ) ? 1 : 2;
1017 int n2 = ( xywnd->GetViewType() == YZ ) ? 1 : 0;
1018 int nAngle = ( xywnd->GetViewType() == XY ) ? CAMERA_YAW : CAMERA_PITCH;
1019 if ( point[n1] || point[n2] ) {
1020 Vector3 angles( Camera_getAngles( camwnd ) );
1021 angles[nAngle] = static_cast<float>( radians_to_degrees( atan2( point[n1], point[n2] ) ) );
1022 Camera_setAngles( camwnd, angles );
1031 unsigned int NewBrushDrag_buttons(){
1035 void XYWnd::NewBrushDrag_Begin( int x, int y ){
1037 m_nNewBrushPressx = x;
1038 m_nNewBrushPressy = y;
1040 m_bNewBrushDrag = true;
1041 GlobalUndoSystem().start();
1044 void XYWnd::NewBrushDrag_End( int x, int y ){
1045 if ( m_NewBrushDrag != 0 ) {
1046 GlobalUndoSystem().finish( "brushDragNew" );
1050 void XYWnd::NewBrushDrag( int x, int y ){
1052 XY_ToPoint( m_nNewBrushPressx, m_nNewBrushPressy, mins );
1053 XY_SnapToGrid( mins );
1054 XY_ToPoint( x, y, maxs );
1055 XY_SnapToGrid( maxs );
1057 int nDim = ( m_viewType == XY ) ? 2 : ( m_viewType == YZ ) ? 0 : 1;
1059 mins[nDim] = float_snapped( Select_getWorkZone().d_work_min[nDim], GetSnapGridSize() );
1060 maxs[nDim] = float_snapped( Select_getWorkZone().d_work_max[nDim], GetSnapGridSize() );
1062 if ( maxs[nDim] <= mins[nDim] ) {
1063 maxs[nDim] = mins[nDim] + GetGridSize();
1066 for ( int i = 0 ; i < 3 ; i++ )
1068 if ( mins[i] == maxs[i] ) {
1069 return; // don't create a degenerate brush
1071 if ( mins[i] > maxs[i] ) {
1072 float temp = mins[i];
1078 if ( m_NewBrushDrag == 0 ) {
1079 NodeSmartReference node( GlobalBrushCreator().createBrush() );
1080 Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->insert( node );
1082 scene::Path brushpath( makeReference( GlobalSceneGraph().root() ) );
1083 brushpath.push( makeReference( *Map_GetWorldspawn( g_map ) ) );
1084 brushpath.push( makeReference( node.get() ) );
1085 selectPath( brushpath, true );
1087 m_NewBrushDrag = node.get_pointer();
1091 //Scene_BrushResize_Selected(GlobalSceneGraph(), aabb_for_minmax(mins, maxs), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()));
1092 Scene_BrushResize_Selected( GlobalSceneGraph(), aabb_for_minmax( mins, maxs ),
1093 g_brush_always_caulk ?
1094 "textures/common/caulk" : TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ) );
1097 void entitycreate_activated( GtkWidget* item ){
1098 scene::Node* world_node = Map_FindWorldspawn( g_map );
1099 const char* entity_name = gtk_label_get_text( GTK_LABEL( GTK_BIN( item )->child ) );
1101 if ( !( world_node && string_equal( entity_name, "worldspawn" ) ) ) {
1102 g_pParentWnd->ActiveXY()->OnEntityCreate( entity_name );
1105 GlobalRadiant().m_pfnMessageBox( GTK_WIDGET( MainFrame_getWindow() ), "There's already a worldspawn in your map!"
1113 void EntityClassMenu_addItem( GtkMenu* menu, const char* name ){
1114 GtkMenuItem* item = GTK_MENU_ITEM( gtk_menu_item_new_with_label( name ) );
1115 g_signal_connect( G_OBJECT( item ), "activate", G_CALLBACK( entitycreate_activated ), item );
1116 gtk_widget_show( GTK_WIDGET( item ) );
1117 menu_add_item( menu, item );
1120 class EntityClassMenuInserter : public EntityClassVisitor
1122 typedef std::pair<GtkMenu*, CopiedString> MenuPair;
1123 typedef std::vector<MenuPair> MenuStack;
1125 CopiedString m_previous;
1127 EntityClassMenuInserter( GtkMenu* menu ){
1128 m_stack.reserve( 2 );
1129 m_stack.push_back( MenuPair( menu, "" ) );
1131 ~EntityClassMenuInserter(){
1132 if ( !string_empty( m_previous.c_str() ) ) {
1133 addItem( m_previous.c_str(), "" );
1136 void visit( EntityClass* e ){
1137 ASSERT_MESSAGE( !string_empty( e->name() ), "entity-class has no name" );
1138 if ( !string_empty( m_previous.c_str() ) ) {
1139 addItem( m_previous.c_str(), e->name() );
1141 m_previous = e->name();
1143 void pushMenu( const CopiedString& name ){
1144 GtkMenuItem* item = GTK_MENU_ITEM( gtk_menu_item_new_with_label( name.c_str() ) );
1145 gtk_widget_show( GTK_WIDGET( item ) );
1146 container_add_widget( GTK_CONTAINER( m_stack.back().first ), GTK_WIDGET( item ) );
1148 GtkMenu* submenu = GTK_MENU( gtk_menu_new() );
1149 gtk_menu_item_set_submenu( item, GTK_WIDGET( submenu ) );
1151 m_stack.push_back( MenuPair( submenu, name ) );
1156 void addItem( const char* name, const char* next ){
1157 const char* underscore = strchr( name, '_' );
1159 if ( underscore != 0 && underscore != name ) {
1160 bool nextEqual = string_equal_n( name, next, ( underscore + 1 ) - name );
1161 const char* parent = m_stack.back().second.c_str();
1163 if ( !string_empty( parent )
1164 && string_length( parent ) == std::size_t( underscore - name )
1165 && string_equal_n( name, parent, underscore - name ) ) { // this is a child
1167 else if ( nextEqual ) {
1168 if ( m_stack.size() == 2 ) {
1171 pushMenu( CopiedString( StringRange( name, underscore ) ) );
1173 else if ( m_stack.size() == 2 ) {
1177 else if ( m_stack.size() == 2 ) {
1181 EntityClassMenu_addItem( m_stack.back().first, name );
1185 void XYWnd::OnContextMenu(){
1186 if ( g_xywindow_globals.m_bRightClick == false ) {
1190 if ( m_mnuDrop == 0 ) { // first time, load it up
1191 GtkMenu* menu = m_mnuDrop = GTK_MENU( gtk_menu_new() );
1193 EntityClassMenuInserter inserter( menu );
1194 GlobalEntityClassManager().forEach( inserter );
1197 gtk_menu_popup( m_mnuDrop, 0, 0, 0, 0, 1, GDK_CURRENT_TIME );
1200 FreezePointer g_xywnd_freezePointer;
1202 unsigned int Move_buttons(){
1206 void XYWnd_moveDelta( int x, int y, unsigned int state, void* data ){
1207 reinterpret_cast<XYWnd*>( data )->EntityCreate_MouseMove( x, y );
1208 reinterpret_cast<XYWnd*>( data )->Scroll( -x, y );
1211 gboolean XYWnd_Move_focusOut( GtkWidget* widget, GdkEventFocus* event, XYWnd* xywnd ){
1216 void XYWnd::Move_Begin(){
1217 if ( m_move_started ) {
1220 m_move_started = true;
1221 g_xywnd_freezePointer.freeze_pointer( m_parent != 0 ? m_parent : MainFrame_getWindow(), m_gl_widget, XYWnd_moveDelta, this );
1222 m_move_focusOut = g_signal_connect( G_OBJECT( m_gl_widget ), "focus_out_event", G_CALLBACK( XYWnd_Move_focusOut ), this );
1225 void XYWnd::Move_End(){
1226 m_move_started = false;
1227 g_xywnd_freezePointer.unfreeze_pointer( m_parent != 0 ? m_parent : MainFrame_getWindow() );
1228 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_move_focusOut );
1231 unsigned int Zoom_buttons(){
1232 return RAD_RBUTTON | RAD_ALT;
1237 void XYWnd_zoomDelta( int x, int y, unsigned int state, void* data ){
1240 while ( abs( g_dragZoom ) > 8 )
1242 if ( g_dragZoom > 0 ) {
1243 reinterpret_cast<XYWnd*>( data )->ZoomOut();
1248 reinterpret_cast<XYWnd*>( data )->ZoomIn();
1255 gboolean XYWnd_Zoom_focusOut( GtkWidget* widget, GdkEventFocus* event, XYWnd* xywnd ){
1260 void XYWnd::Zoom_Begin(){
1261 if ( m_zoom_started ) {
1264 m_zoom_started = true;
1266 g_xywnd_freezePointer.freeze_pointer( m_parent != 0 ? m_parent : MainFrame_getWindow(), m_gl_widget, XYWnd_zoomDelta, this );
1267 m_zoom_focusOut = g_signal_connect( G_OBJECT( m_gl_widget ), "focus_out_event", G_CALLBACK( XYWnd_Zoom_focusOut ), this );
1270 void XYWnd::Zoom_End(){
1271 m_zoom_started = false;
1272 g_xywnd_freezePointer.unfreeze_pointer( m_parent != 0 ? m_parent : MainFrame_getWindow() );
1273 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_zoom_focusOut );
1276 // makes sure the selected brush or camera is in view
1277 void XYWnd::PositionView( const Vector3& position ){
1278 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1279 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1281 m_vOrigin[nDim1] = position[nDim1];
1282 m_vOrigin[nDim2] = position[nDim2];
1286 XYWnd_Update( *this );
1289 void XYWnd::SetViewType( VIEWTYPE viewType ){
1290 m_viewType = viewType;
1293 if ( m_parent != 0 ) {
1294 gtk_window_set_title( m_parent, ViewType_getTitle( m_viewType ) );
1299 inline WindowVector WindowVector_forInteger( int x, int y ){
1300 return WindowVector( static_cast<float>( x ), static_cast<float>( y ) );
1303 void XYWnd::mouseDown( const WindowVector& position, ButtonIdentifier button, ModifierFlags modifiers ){
1304 XY_MouseDown( static_cast<int>( position.x() ), static_cast<int>( position.y() ), buttons_for_button_and_modifiers( button, modifiers ) );
1306 void XYWnd::XY_MouseDown( int x, int y, unsigned int buttons ){
1307 if ( buttons == Move_buttons() ) {
1309 EntityCreate_MouseDown( x, y );
1311 else if ( buttons == Zoom_buttons() ) {
1314 else if ( ClipMode() && ( buttons == Clipper_buttons() || buttons == Clipper_quick_buttons() ) ) {
1315 Clipper_OnLButtonDown( x, y );
1317 else if ( !ClipMode() && buttons == Clipper_quick_buttons() ) {
1319 g_quick_clipper = true;
1320 Clipper_OnLButtonDown( x, y );
1322 else if ( buttons == NewBrushDrag_buttons() && GlobalSelectionSystem().countSelected() == 0 ) {
1323 NewBrushDrag_Begin( x, y );
1325 // control mbutton = move camera
1326 else if ( buttons == MoveCamera_buttons() ) {
1327 XYWnd_PositionCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1329 // mbutton = angle camera
1330 else if ( buttons == OrientCamera_buttons() ) {
1331 XYWnd_OrientCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1335 m_window_observer->onMouseDown( WindowVector_forInteger( x, y ), button_for_flags( buttons ), modifiers_for_flags( buttons ) );
1339 void XYWnd::XY_MouseUp( int x, int y, unsigned int buttons ){
1340 if ( m_move_started ) {
1342 EntityCreate_MouseUp( x, y );
1344 else if ( m_zoom_started ) {
1347 else if ( ClipMode() && ( buttons == Clipper_buttons() || buttons == Clipper_quick_buttons() ) ) {
1348 Clipper_OnLButtonUp( x, y );
1350 else if ( m_bNewBrushDrag ) {
1351 m_bNewBrushDrag = false;
1352 NewBrushDrag_End( x, y );
1353 if ( m_NewBrushDrag == 0 ) {
1354 //L button w/o created brush = tunnel selection
1355 m_window_observer->onMouseUp( WindowVector_forInteger( x, y ), button_for_flags( buttons ), modifiers_for_flags( buttons ) );
1360 m_window_observer->onMouseUp( WindowVector_forInteger( x, y ), button_for_flags( buttons ), modifiers_for_flags( buttons ) );
1364 void XYWnd::XY_MouseMoved( int x, int y, unsigned int buttons ){
1365 // rbutton = drag xy origin
1366 if ( m_move_started ) {
1369 else if ( m_zoom_started ) {
1372 else if ( ClipMode() && g_pMovingClip != 0 ) {
1373 Clipper_OnMouseMoved( x, y );
1375 // lbutton without selection = drag new brush
1376 else if ( m_bNewBrushDrag ) {
1377 NewBrushDrag( x, y );
1380 // control mbutton = move camera
1381 else if ( getButtonState() == MoveCamera_buttons() ) {
1382 XYWnd_PositionCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1385 // mbutton = angle camera
1386 else if ( getButtonState() == OrientCamera_buttons() ) {
1387 XYWnd_OrientCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1392 m_window_observer->onMouseMotion( WindowVector_forInteger( x, y ), modifiers_for_flags( buttons ) );
1394 m_mousePosition[0] = m_mousePosition[1] = m_mousePosition[2] = 0.0;
1395 XY_ToPoint( x, y, m_mousePosition );
1396 XY_SnapToGrid( m_mousePosition );
1398 StringOutputStream status( 64 );
1399 status << "x:: " << FloatFormat( m_mousePosition[0], 6, 1 )
1400 << " y:: " << FloatFormat( m_mousePosition[1], 6, 1 )
1401 << " z:: " << FloatFormat( m_mousePosition[2], 6, 1 );
1402 g_pParentWnd->SetStatusText( g_pParentWnd->m_position_status, status.c_str() );
1404 if ( g_bCrossHairs ) {
1405 XYWnd_Update( *this );
1408 Clipper_Crosshair_OnMouseMoved( x, y );
1412 void XYWnd::EntityCreate_MouseDown( int x, int y ){
1413 m_entityCreate = true;
1414 m_entityCreate_x = x;
1415 m_entityCreate_y = y;
1418 void XYWnd::EntityCreate_MouseMove( int x, int y ){
1419 if ( m_entityCreate && ( m_entityCreate_x != x || m_entityCreate_y != y ) ) {
1420 m_entityCreate = false;
1424 void XYWnd::EntityCreate_MouseUp( int x, int y ){
1425 if ( m_entityCreate ) {
1426 m_entityCreate = false;
1431 inline float screen_normalised( int pos, unsigned int size ){
1432 return ( ( 2.0f * pos ) / size ) - 1.0f;
1435 inline float normalised_to_world( float normalised, float world_origin, float normalised2world_scale ){
1436 return world_origin + normalised * normalised2world_scale;
1440 // TTimo: watch it, this doesn't init one of the 3 coords
1441 void XYWnd::XY_ToPoint( int x, int y, Vector3& point ){
1442 float normalised2world_scale_x = m_nWidth / 2 / m_fScale;
1443 float normalised2world_scale_y = m_nHeight / 2 / m_fScale;
1444 if ( m_viewType == XY ) {
1445 point[0] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[0], normalised2world_scale_x );
1446 point[1] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[1], normalised2world_scale_y );
1448 else if ( m_viewType == YZ ) {
1449 point[1] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[1], normalised2world_scale_x );
1450 point[2] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[2], normalised2world_scale_y );
1454 point[0] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[0], normalised2world_scale_x );
1455 point[2] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[2], normalised2world_scale_y );
1459 void XYWnd::XY_SnapToGrid( Vector3& point ){
1460 if ( m_viewType == XY ) {
1461 point[0] = float_snapped( point[0], GetSnapGridSize() );
1462 point[1] = float_snapped( point[1], GetSnapGridSize() );
1464 else if ( m_viewType == YZ ) {
1465 point[1] = float_snapped( point[1], GetSnapGridSize() );
1466 point[2] = float_snapped( point[2], GetSnapGridSize() );
1470 point[0] = float_snapped( point[0], GetSnapGridSize() );
1471 point[2] = float_snapped( point[2], GetSnapGridSize() );
1475 void XYWnd::XY_LoadBackgroundImage( const char *name ){
1476 const char* relative = path_make_relative( name, GlobalFileSystem().findRoot( name ) );
1477 if ( relative == name ) {
1478 globalOutputStream() << "WARNING: could not extract the relative path, using full path instead\n";
1481 char fileNameWithoutExt[512];
1482 strncpy( fileNameWithoutExt, relative, sizeof( fileNameWithoutExt ) - 1 );
1483 fileNameWithoutExt[512 - 1] = '\0';
1484 fileNameWithoutExt[strlen( fileNameWithoutExt ) - 4] = '\0';
1486 Image *image = QERApp_LoadImage( 0, fileNameWithoutExt );
1488 globalOutputStream() << "Could not load texture " << fileNameWithoutExt << "\n";
1491 g_pParentWnd->ActiveXY()->m_tex = (qtexture_t*)malloc( sizeof( qtexture_t ) );
1492 LoadTextureRGBA( g_pParentWnd->ActiveXY()->XYWnd::m_tex, image->getRGBAPixels(), image->getWidth(), image->getHeight() );
1493 globalOutputStream() << "Loaded background texture " << relative << "\n";
1494 g_pParentWnd->ActiveXY()->m_backgroundActivated = true;
1497 switch ( g_pParentWnd->ActiveXY()->m_viewType )
1514 Select_GetBounds( min, max );
1515 g_pParentWnd->ActiveXY()->m_xmin = min[m_ix];
1516 g_pParentWnd->ActiveXY()->m_ymin = min[m_iy];
1517 g_pParentWnd->ActiveXY()->m_xmax = max[m_ix];
1518 g_pParentWnd->ActiveXY()->m_ymax = max[m_iy];
1521 void XYWnd::XY_DisableBackground( void ){
1522 g_pParentWnd->ActiveXY()->m_backgroundActivated = false;
1523 if ( g_pParentWnd->ActiveXY()->m_tex ) {
1524 free( g_pParentWnd->ActiveXY()->m_tex );
1526 g_pParentWnd->ActiveXY()->m_tex = NULL;
1529 void WXY_BackgroundSelect( void ){
1530 bool brushesSelected = Scene_countSelectedBrushes( GlobalSceneGraph() ) != 0;
1531 if ( !brushesSelected ) {
1532 gtk_MessageBox( 0, "You have to select some brushes to get the bounding box for.\n",
1533 "No selection", eMB_OK, eMB_ICONERROR );
1537 const char *filename = file_dialog( GTK_WIDGET( MainFrame_getWindow() ), TRUE, "Background Image", NULL, NULL );
1538 g_pParentWnd->ActiveXY()->XY_DisableBackground();
1540 g_pParentWnd->ActiveXY()->XY_LoadBackgroundImage( filename );
1545 ============================================================================
1549 ============================================================================
1558 double two_to_the_power( int power ){
1559 return pow( 2.0f, power );
1562 void XYWnd::XY_DrawAxis( void ){
1563 if ( g_xywindow_globals_private.show_axis ) {
1564 const char g_AxisName[3] = { 'X', 'Y', 'Z' };
1565 const int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1566 const int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1567 const int w = ( m_nWidth / 2 / m_fScale );
1568 const int h = ( m_nHeight / 2 / m_fScale );
1570 const Vector3& colourX = ( m_viewType == YZ ) ? g_xywindow_globals.AxisColorY : g_xywindow_globals.AxisColorX;
1571 const Vector3& colourY = ( m_viewType == XY ) ? g_xywindow_globals.AxisColorY : g_xywindow_globals.AxisColorZ;
1573 // draw two lines with corresponding axis colors to highlight current view
1574 // horizontal line: nDim1 color
1576 glBegin( GL_LINES );
1577 glColor3fv( vector3_to_array( colourX ) );
1578 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1579 glVertex2f( m_vOrigin[nDim1] - w + 65 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1581 glVertex2f( 32 / m_fScale, 0 );
1582 glColor3fv( vector3_to_array( colourY ) );
1583 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1584 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 20 / m_fScale );
1586 glVertex2f( 0, 32 / m_fScale );
1589 // now print axis symbols
1590 glColor3fv( vector3_to_array( colourX ) );
1591 glRasterPos2f( m_vOrigin[nDim1] - w + 55 / m_fScale, m_vOrigin[nDim2] + h - 55 / m_fScale );
1592 GlobalOpenGL().drawChar( g_AxisName[nDim1] );
1593 glRasterPos2f( 28 / m_fScale, -10 / m_fScale );
1594 GlobalOpenGL().drawChar( g_AxisName[nDim1] );
1595 glColor3fv( vector3_to_array( colourY ) );
1596 glRasterPos2f( m_vOrigin[nDim1] - w + 25 / m_fScale, m_vOrigin[nDim2] + h - 30 / m_fScale );
1597 GlobalOpenGL().drawChar( g_AxisName[nDim2] );
1598 glRasterPos2f( -10 / m_fScale, 28 / m_fScale );
1599 GlobalOpenGL().drawChar( g_AxisName[nDim2] );
1603 void XYWnd::XY_DrawBackground( void ){
1604 glPushAttrib( GL_ALL_ATTRIB_BITS );
1606 glEnable( GL_TEXTURE_2D );
1607 glEnable( GL_BLEND );
1608 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
1609 glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1610 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
1611 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
1613 glPolygonMode( GL_FRONT, GL_FILL );
1615 glBindTexture( GL_TEXTURE_2D, m_tex->texture_number );
1616 glBegin( GL_QUADS );
1618 glColor4f( 1.0, 1.0, 1.0, m_alpha );
1619 glTexCoord2f( 0.0, 1.0 );
1620 glVertex2f( m_xmin, m_ymin );
1622 glTexCoord2f( 1.0, 1.0 );
1623 glVertex2f( m_xmax, m_ymin );
1625 glTexCoord2f( 1.0, 0.0 );
1626 glVertex2f( m_xmax, m_ymax );
1628 glTexCoord2f( 0.0, 0.0 );
1629 glVertex2f( m_xmin, m_ymax );
1632 glBindTexture( GL_TEXTURE_2D, 0 );
1637 void XYWnd::XY_DrawGrid( void ) {
1638 float x, y, xb, xe, yb, ye;
1641 float step, minor_step, stepx, stepy;
1642 step = minor_step = stepx = stepy = GetGridSize();
1644 int minor_power = Grid_getPower();
1647 while ( ( minor_step * m_fScale ) <= 4.0f ) { // make sure minor grid spacing is at least 4 pixels on the screen
1651 int power = minor_power;
1652 while ( ( power % 3 ) != 0 || ( step * m_fScale ) <= 32.0f ) { // make sure major grid spacing is at least 32 pixels on the screen
1654 step = float(two_to_the_power( power ) );
1656 mask = ( 1 << ( power - minor_power ) ) - 1;
1657 while ( ( stepx * m_fScale ) <= 32.0f ) // text step x must be at least 32
1659 while ( ( stepy * m_fScale ) <= 32.0f ) // text step y must be at least 32
1662 a = ( ( GetSnapGridSize() > 0.0f ) ? 1.0f : 0.3f );
1664 glDisable( GL_TEXTURE_2D );
1665 glDisable( GL_TEXTURE_1D );
1666 glDisable( GL_DEPTH_TEST );
1667 glDisable( GL_BLEND );
1670 w = ( m_nWidth / 2 / m_fScale );
1671 h = ( m_nHeight / 2 / m_fScale );
1673 const int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1674 const int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1676 xb = m_vOrigin[nDim1] - w;
1677 if ( xb < region_mins[nDim1] ) {
1678 xb = region_mins[nDim1];
1680 xb = step * floor( xb / step );
1682 xe = m_vOrigin[nDim1] + w;
1683 if ( xe > region_maxs[nDim1] ) {
1684 xe = region_maxs[nDim1];
1686 xe = step * ceil( xe / step );
1688 yb = m_vOrigin[nDim2] - h;
1689 if ( yb < region_mins[nDim2] ) {
1690 yb = region_mins[nDim2];
1692 yb = step * floor( yb / step );
1694 ye = m_vOrigin[nDim2] + h;
1695 if ( ye > region_maxs[nDim2] ) {
1696 ye = region_maxs[nDim2];
1698 ye = step * ceil( ye / step );
1700 #define COLORS_DIFFER( a,b ) \
1701 ( ( a )[0] != ( b )[0] || \
1702 ( a )[1] != ( b )[1] || \
1703 ( a )[2] != ( b )[2] )
1706 // draw minor blocks
1707 if ( g_xywindow_globals_private.d_showgrid || a < 1.0f ) {
1709 glEnable( GL_BLEND );
1712 if ( COLORS_DIFFER( g_xywindow_globals.color_gridminor, g_xywindow_globals.color_gridback ) ) {
1713 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridminor, a ) ) );
1715 glBegin( GL_LINES );
1717 for ( x = xb ; x < xe ; x += minor_step, ++i ) {
1718 if ( ( i & mask ) != 0 ) {
1719 glVertex2f( x, yb );
1720 glVertex2f( x, ye );
1724 for ( y = yb ; y < ye ; y += minor_step, ++i ) {
1725 if ( ( i & mask ) != 0 ) {
1726 glVertex2f( xb, y );
1727 glVertex2f( xe, y );
1733 // draw major blocks
1734 if ( COLORS_DIFFER( g_xywindow_globals.color_gridmajor, g_xywindow_globals.color_gridminor ) ) {
1735 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridmajor, a ) ) );
1737 glBegin( GL_LINES );
1738 for ( x = xb ; x <= xe ; x += step ) {
1739 glVertex2f( x, yb );
1740 glVertex2f( x, ye );
1742 for ( y = yb ; y <= ye ; y += step ) {
1743 glVertex2f( xb, y );
1744 glVertex2f( xe, y );
1750 glDisable( GL_BLEND );
1754 // draw coordinate text if needed
1755 if ( g_xywindow_globals_private.show_coordinates ) {
1756 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridtext, 1.0f ) ) );
1757 float offx = m_vOrigin[nDim2] + h - ( 4 + GlobalOpenGL().m_font->getPixelAscent() ) / m_fScale;
1758 float offy = m_vOrigin[nDim1] - w + 4 / m_fScale;
1759 for ( x = xb - fmod( xb, stepx ); x <= xe ; x += stepx ) {
1760 glRasterPos2f( x, offx );
1761 sprintf( text, "%g", x );
1762 GlobalOpenGL().drawString( text );
1764 for ( y = yb - fmod( yb, stepy ); y <= ye ; y += stepy ) {
1765 glRasterPos2f( offy, y );
1766 sprintf( text, "%g", y );
1767 GlobalOpenGL().drawString( text );
1771 glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) );
1774 // we do this part (the old way) only if show_axis is disabled
1775 if ( !g_xywindow_globals_private.show_axis ) {
1776 glRasterPos2f( m_vOrigin[nDim1] - w + 35 / m_fScale, m_vOrigin[nDim2] + h - 20 / m_fScale );
1778 GlobalOpenGL().drawString( ViewType_getTitle( m_viewType ) );
1782 XYWnd::XY_DrawAxis();
1784 // show current work zone?
1785 // the work zone is used to place dropped points and brushes
1786 if ( g_xywindow_globals_private.d_show_work ) {
1787 glColor4f( 1.0f, 0.0f, 0.0f, 1.0f );
1788 glBegin( GL_LINES );
1789 glVertex2f( xb, Select_getWorkZone().d_work_min[nDim2] );
1790 glVertex2f( xe, Select_getWorkZone().d_work_min[nDim2] );
1791 glVertex2f( xb, Select_getWorkZone().d_work_max[nDim2] );
1792 glVertex2f( xe, Select_getWorkZone().d_work_max[nDim2] );
1793 glVertex2f( Select_getWorkZone().d_work_min[nDim1], yb );
1794 glVertex2f( Select_getWorkZone().d_work_min[nDim1], ye );
1795 glVertex2f( Select_getWorkZone().d_work_max[nDim1], yb );
1796 glVertex2f( Select_getWorkZone().d_work_max[nDim1], ye );
1806 void XYWnd::XY_DrawBlockGrid(){
1807 if ( Map_FindWorldspawn( g_map ) == 0 ) {
1810 const char *value = Node_getEntity( *Map_GetWorldspawn( g_map ) )->getKeyValue( "_blocksize" );
1811 if ( strlen( value ) ) {
1812 sscanf( value, "%i", &g_xywindow_globals_private.blockSize );
1815 if ( !g_xywindow_globals_private.blockSize || g_xywindow_globals_private.blockSize > 65536 || g_xywindow_globals_private.blockSize < 1024 ) {
1816 // don't use custom blocksize if it is less than the default, or greater than the maximum world coordinate
1817 g_xywindow_globals_private.blockSize = 1024;
1820 float x, y, xb, xe, yb, ye;
1824 glDisable( GL_TEXTURE_2D );
1825 glDisable( GL_TEXTURE_1D );
1826 glDisable( GL_DEPTH_TEST );
1827 glDisable( GL_BLEND );
1829 w = ( m_nWidth / 2 / m_fScale );
1830 h = ( m_nHeight / 2 / m_fScale );
1832 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1833 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1835 xb = m_vOrigin[nDim1] - w;
1836 if ( xb < region_mins[nDim1] ) {
1837 xb = region_mins[nDim1];
1839 xb = static_cast<float>( g_xywindow_globals_private.blockSize * floor( xb / g_xywindow_globals_private.blockSize ) );
1841 xe = m_vOrigin[nDim1] + w;
1842 if ( xe > region_maxs[nDim1] ) {
1843 xe = region_maxs[nDim1];
1845 xe = static_cast<float>( g_xywindow_globals_private.blockSize * ceil( xe / g_xywindow_globals_private.blockSize ) );
1847 yb = m_vOrigin[nDim2] - h;
1848 if ( yb < region_mins[nDim2] ) {
1849 yb = region_mins[nDim2];
1851 yb = static_cast<float>( g_xywindow_globals_private.blockSize * floor( yb / g_xywindow_globals_private.blockSize ) );
1853 ye = m_vOrigin[nDim2] + h;
1854 if ( ye > region_maxs[nDim2] ) {
1855 ye = region_maxs[nDim2];
1857 ye = static_cast<float>( g_xywindow_globals_private.blockSize * ceil( ye / g_xywindow_globals_private.blockSize ) );
1859 // draw major blocks
1861 glColor3fv( vector3_to_array( g_xywindow_globals.color_gridblock ) );
1864 glBegin( GL_LINES );
1866 for ( x = xb ; x <= xe ; x += g_xywindow_globals_private.blockSize )
1868 glVertex2f( x, yb );
1869 glVertex2f( x, ye );
1872 if ( m_viewType == XY ) {
1873 for ( y = yb ; y <= ye ; y += g_xywindow_globals_private.blockSize )
1875 glVertex2f( xb, y );
1876 glVertex2f( xe, y );
1883 // draw coordinate text if needed
1885 if ( m_viewType == XY && m_fScale > .1 ) {
1886 for ( x = xb ; x < xe ; x += g_xywindow_globals_private.blockSize )
1887 for ( y = yb ; y < ye ; y += g_xywindow_globals_private.blockSize )
1889 glRasterPos2f( x + ( g_xywindow_globals_private.blockSize / 2 ), y + ( g_xywindow_globals_private.blockSize / 2 ) );
1890 sprintf( text, "%i,%i",(int)floor( x / g_xywindow_globals_private.blockSize ), (int)floor( y / g_xywindow_globals_private.blockSize ) );
1891 GlobalOpenGL().drawString( text );
1895 glColor4f( 0, 0, 0, 0 );
1898 void XYWnd::DrawCameraIcon( const Vector3& origin, const Vector3& angles ){
1899 float x, y, fov, box;
1902 fov = 48 / m_fScale;
1903 box = 16 / m_fScale;
1905 if ( m_viewType == XY ) {
1908 a = degrees_to_radians( angles[CAMERA_YAW] );
1910 else if ( m_viewType == YZ ) {
1913 a = degrees_to_radians( angles[CAMERA_PITCH] );
1919 a = degrees_to_radians( angles[CAMERA_PITCH] );
1922 glColor3f( 0.0, 0.0, 1.0 );
1923 glBegin( GL_LINE_STRIP );
1924 glVertex3f( x - box,y,0 );
1925 glVertex3f( x,y + ( box / 2 ),0 );
1926 glVertex3f( x + box,y,0 );
1927 glVertex3f( x,y - ( box / 2 ),0 );
1928 glVertex3f( x - box,y,0 );
1929 glVertex3f( x + box,y,0 );
1932 glBegin( GL_LINE_STRIP );
1933 glVertex3f( x + static_cast<float>( fov * cos( a + c_pi / 4 ) ), y + static_cast<float>( fov * sin( a + c_pi / 4 ) ), 0 );
1934 glVertex3f( x, y, 0 );
1935 glVertex3f( x + static_cast<float>( fov * cos( a - c_pi / 4 ) ), y + static_cast<float>( fov * sin( a - c_pi / 4 ) ), 0 );
1941 float Betwixt( float f1, float f2 ){
1943 return f2 + ( ( f1 - f2 ) / 2 );
1946 return f1 + ( ( f2 - f1 ) / 2 );
1951 // can be greatly simplified but per usual i am in a hurry
1952 // which is not an excuse, just a fact
1953 void XYWnd::PaintSizeInfo( int nDim1, int nDim2, Vector3& vMinBounds, Vector3& vMaxBounds ){
1954 if ( vector3_equal( vMinBounds, vMaxBounds ) ) {
1957 const char* g_pDimStrings[] = {"x:", "y:", "z:"};
1958 typedef const char* OrgStrings[2];
1959 const OrgStrings g_pOrgStrings[] = { { "x:", "y:", }, { "x:", "z:", }, { "y:", "z:", } };
1961 Vector3 vSize( vector3_subtracted( vMaxBounds, vMinBounds ) );
1963 glColor3f( g_xywindow_globals.color_selbrushes[0] * .65f,
1964 g_xywindow_globals.color_selbrushes[1] * .65f,
1965 g_xywindow_globals.color_selbrushes[2] * .65f );
1967 StringOutputStream dimensions( 16 );
1969 if ( m_viewType == XY ) {
1970 glBegin( GL_LINES );
1972 glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f );
1973 glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
1975 glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
1976 glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
1978 glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f );
1979 glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
1982 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2], 0.0f );
1983 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f );
1985 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f );
1986 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f );
1988 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2], 0.0f );
1989 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f );
1993 glRasterPos3f( Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), vMinBounds[nDim2] - 20.0f / m_fScale, 0.0f );
1994 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
1995 GlobalOpenGL().drawString( dimensions.c_str() );
1998 glRasterPos3f( vMaxBounds[nDim1] + 16.0f / m_fScale, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ), 0.0f );
1999 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
2000 GlobalOpenGL().drawString( dimensions.c_str() );
2003 glRasterPos3f( vMinBounds[nDim1] + 4, vMaxBounds[nDim2] + 8 / m_fScale, 0.0f );
2004 dimensions << "(" << g_pOrgStrings[0][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[0][1] << vMaxBounds[nDim2] << ")";
2005 GlobalOpenGL().drawString( dimensions.c_str() );
2007 else if ( m_viewType == XZ ) {
2008 glBegin( GL_LINES );
2010 glVertex3f( vMinBounds[nDim1], 0, vMinBounds[nDim2] - 6.0f / m_fScale );
2011 glVertex3f( vMinBounds[nDim1], 0, vMinBounds[nDim2] - 10.0f / m_fScale );
2013 glVertex3f( vMinBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale );
2014 glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale );
2016 glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 6.0f / m_fScale );
2017 glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale );
2020 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, 0,vMinBounds[nDim2] );
2021 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMinBounds[nDim2] );
2023 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMinBounds[nDim2] );
2024 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMaxBounds[nDim2] );
2026 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, 0,vMaxBounds[nDim2] );
2027 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMaxBounds[nDim2] );
2031 glRasterPos3f( Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), 0, vMinBounds[nDim2] - 20.0f / m_fScale );
2032 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
2033 GlobalOpenGL().drawString( dimensions.c_str() );
2036 glRasterPos3f( vMaxBounds[nDim1] + 16.0f / m_fScale, 0, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ) );
2037 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
2038 GlobalOpenGL().drawString( dimensions.c_str() );
2041 glRasterPos3f( vMinBounds[nDim1] + 4, 0, vMaxBounds[nDim2] + 8 / m_fScale );
2042 dimensions << "(" << g_pOrgStrings[1][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[1][1] << vMaxBounds[nDim2] << ")";
2043 GlobalOpenGL().drawString( dimensions.c_str() );
2047 glBegin( GL_LINES );
2049 glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale );
2050 glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2052 glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2053 glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2055 glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale );
2056 glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2059 glVertex3f( 0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2] );
2060 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2] );
2062 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2] );
2063 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2] );
2065 glVertex3f( 0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2] );
2066 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2] );
2070 glRasterPos3f( 0, Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), vMinBounds[nDim2] - 20.0f / m_fScale );
2071 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
2072 GlobalOpenGL().drawString( dimensions.c_str() );
2075 glRasterPos3f( 0, vMaxBounds[nDim1] + 16.0f / m_fScale, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ) );
2076 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
2077 GlobalOpenGL().drawString( dimensions.c_str() );
2080 glRasterPos3f( 0, vMinBounds[nDim1] + 4.0f, vMaxBounds[nDim2] + 8 / m_fScale );
2081 dimensions << "(" << g_pOrgStrings[2][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[2][1] << vMaxBounds[nDim2] << ")";
2082 GlobalOpenGL().drawString( dimensions.c_str() );
2086 class XYRenderer : public Renderer
2094 unsigned int m_highlight;
2098 XYRenderer( RenderStateFlags globalstate, Shader* selected ) :
2099 m_globalstate( globalstate ),
2100 m_state_selected( selected ){
2101 ASSERT_NOTNULL( selected );
2102 m_state_stack.push_back( state_type() );
2105 void SetState( Shader* state, EStyle style ){
2106 ASSERT_NOTNULL( state );
2107 if ( style == eWireframeOnly ) {
2108 m_state_stack.back().m_state = state;
2111 const EStyle getStyle() const {
2112 return eWireframeOnly;
2115 m_state_stack.push_back( m_state_stack.back() );
2118 ASSERT_MESSAGE( !m_state_stack.empty(), "popping empty stack" );
2119 m_state_stack.pop_back();
2121 void Highlight( EHighlightMode mode, bool bEnable = true ){
2123 ? m_state_stack.back().m_highlight |= mode
2124 : m_state_stack.back().m_highlight &= ~mode;
2126 void addRenderable( const OpenGLRenderable& renderable, const Matrix4& localToWorld ){
2127 if ( m_state_stack.back().m_highlight & ePrimitive ) {
2128 m_state_selected->addRenderable( renderable, localToWorld );
2132 m_state_stack.back().m_state->addRenderable( renderable, localToWorld );
2136 void render( const Matrix4& modelview, const Matrix4& projection ){
2137 GlobalShaderCache().render( m_globalstate, modelview, projection );
2140 std::vector<state_type> m_state_stack;
2141 RenderStateFlags m_globalstate;
2142 Shader* m_state_selected;
2145 void XYWnd::updateProjection(){
2146 m_projection[0] = 1.0f / static_cast<float>( m_nWidth / 2 );
2147 m_projection[5] = 1.0f / static_cast<float>( m_nHeight / 2 );
2148 m_projection[10] = 1.0f / ( g_MaxWorldCoord * m_fScale );
2150 m_projection[12] = 0.0f;
2151 m_projection[13] = 0.0f;
2152 m_projection[14] = -1.0f;
2164 m_projection[11] = 0.0f;
2166 m_projection[15] = 1.0f;
2168 m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight );
2171 // note: modelview matrix must have a uniform scale, otherwise strange things happen when rendering the rotation manipulator.
2172 void XYWnd::updateModelview(){
2173 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
2174 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
2177 m_modelview[12] = -m_vOrigin[nDim1] * m_fScale;
2178 m_modelview[13] = -m_vOrigin[nDim2] * m_fScale;
2179 m_modelview[14] = g_MaxWorldCoord * m_fScale;
2182 switch ( m_viewType )
2185 m_modelview[0] = m_fScale;
2190 m_modelview[5] = m_fScale;
2195 m_modelview[10] = -m_fScale;
2198 m_modelview[0] = m_fScale;
2204 m_modelview[6] = m_fScale;
2207 m_modelview[9] = m_fScale;
2208 m_modelview[10] = 0;
2213 m_modelview[2] = -m_fScale;
2215 m_modelview[4] = m_fScale;
2220 m_modelview[9] = m_fScale;
2221 m_modelview[10] = 0;
2225 m_modelview[3] = m_modelview[7] = m_modelview[11] = 0;
2226 m_modelview[15] = 1;
2228 m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight );
2237 //#define DBG_SCENEDUMP
2239 void XYWnd::XY_Draw(){
2243 glViewport( 0, 0, m_nWidth, m_nHeight );
2244 glClearColor( g_xywindow_globals.color_gridback[0],
2245 g_xywindow_globals.color_gridback[1],
2246 g_xywindow_globals.color_gridback[2],0 );
2248 glClear( GL_COLOR_BUFFER_BIT );
2254 glMatrixMode( GL_PROJECTION );
2255 glLoadMatrixf( reinterpret_cast<const float*>( &m_projection ) );
2257 glMatrixMode( GL_MODELVIEW );
2259 glScalef( m_fScale, m_fScale, 1 );
2260 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
2261 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
2262 glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 );
2264 glDisable( GL_LINE_STIPPLE );
2266 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2267 glDisableClientState( GL_NORMAL_ARRAY );
2268 glDisableClientState( GL_COLOR_ARRAY );
2269 glDisable( GL_TEXTURE_2D );
2270 glDisable( GL_LIGHTING );
2271 glDisable( GL_COLOR_MATERIAL );
2272 glDisable( GL_DEPTH_TEST );
2274 if ( m_backgroundActivated ) {
2275 XY_DrawBackground();
2279 if ( g_xywindow_globals_private.show_blocks ) {
2283 glLoadMatrixf( reinterpret_cast<const float*>( &m_modelview ) );
2285 unsigned int globalstate = RENDER_COLOURARRAY | RENDER_COLOURWRITE | RENDER_POLYGONSMOOTH | RENDER_LINESMOOTH;
2286 if ( !g_xywindow_globals.m_bNoStipple ) {
2287 globalstate |= RENDER_LINESTIPPLE;
2291 XYRenderer renderer( globalstate, m_state_selected );
2293 Scene_Render( renderer, m_view );
2295 GlobalOpenGL_debugAssertNoErrors();
2296 renderer.render( m_modelview, m_projection );
2297 GlobalOpenGL_debugAssertNoErrors();
2300 glDepthMask( GL_FALSE );
2302 GlobalOpenGL_debugAssertNoErrors();
2304 glLoadMatrixf( reinterpret_cast<const float*>( &m_modelview ) );
2306 GlobalOpenGL_debugAssertNoErrors();
2307 glDisable( GL_LINE_STIPPLE );
2308 GlobalOpenGL_debugAssertNoErrors();
2310 GlobalOpenGL_debugAssertNoErrors();
2311 if ( GlobalOpenGL().GL_1_3() ) {
2312 glActiveTexture( GL_TEXTURE0 );
2313 glClientActiveTexture( GL_TEXTURE0 );
2315 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2316 GlobalOpenGL_debugAssertNoErrors();
2317 glDisableClientState( GL_NORMAL_ARRAY );
2318 GlobalOpenGL_debugAssertNoErrors();
2319 glDisableClientState( GL_COLOR_ARRAY );
2320 GlobalOpenGL_debugAssertNoErrors();
2321 glDisable( GL_TEXTURE_2D );
2322 GlobalOpenGL_debugAssertNoErrors();
2323 glDisable( GL_LIGHTING );
2324 GlobalOpenGL_debugAssertNoErrors();
2325 glDisable( GL_COLOR_MATERIAL );
2326 GlobalOpenGL_debugAssertNoErrors();
2328 GlobalOpenGL_debugAssertNoErrors();
2332 if ( g_xywindow_globals_private.m_bSizePaint && GlobalSelectionSystem().countSelected() != 0 ) {
2334 Select_GetBounds( min, max );
2335 PaintSizeInfo( nDim1, nDim2, min, max );
2338 if ( g_bCrossHairs ) {
2339 glColor4f( 0.2f, 0.9f, 0.2f, 0.8f );
2340 glBegin( GL_LINES );
2341 if ( m_viewType == XY ) {
2342 glVertex2f( 2.0f * g_MinWorldCoord, m_mousePosition[1] );
2343 glVertex2f( 2.0f * g_MaxWorldCoord, m_mousePosition[1] );
2344 glVertex2f( m_mousePosition[0], 2.0f * g_MinWorldCoord );
2345 glVertex2f( m_mousePosition[0], 2.0f * g_MaxWorldCoord );
2347 else if ( m_viewType == YZ ) {
2348 glVertex3f( m_mousePosition[0], 2.0f * g_MinWorldCoord, m_mousePosition[2] );
2349 glVertex3f( m_mousePosition[0], 2.0f * g_MaxWorldCoord, m_mousePosition[2] );
2350 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MinWorldCoord );
2351 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MaxWorldCoord );
2355 glVertex3f( 2.0f * g_MinWorldCoord, m_mousePosition[1], m_mousePosition[2] );
2356 glVertex3f( 2.0f * g_MaxWorldCoord, m_mousePosition[1], m_mousePosition[2] );
2357 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MinWorldCoord );
2358 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MaxWorldCoord );
2364 GlobalClipPoints_Draw( m_fScale );
2367 GlobalOpenGL_debugAssertNoErrors();
2371 glScalef( m_fScale, m_fScale, 1 );
2372 glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 );
2374 DrawCameraIcon( Camera_getOrigin( *g_pParentWnd->GetCamWnd() ), Camera_getAngles( *g_pParentWnd->GetCamWnd() ) );
2376 Feedback_draw2D( m_viewType );
2378 if ( g_xywindow_globals_private.show_outline ) {
2380 glMatrixMode( GL_PROJECTION );
2382 glOrtho( 0, m_nWidth, 0, m_nHeight, 0, 1 );
2384 glMatrixMode( GL_MODELVIEW );
2387 // four view mode doesn't colorize
2388 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) {
2389 glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) );
2393 switch ( m_viewType )
2396 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorX ) );
2399 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorY ) );
2402 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorZ ) );
2406 glBegin( GL_LINE_LOOP );
2407 glVertex2f( 0.5, 0.5 );
2408 glVertex2f( m_nWidth - 0.5, 1 );
2409 glVertex2f( m_nWidth - 0.5, m_nHeight - 0.5 );
2410 glVertex2f( 0.5, m_nHeight - 0.5 );
2415 GlobalOpenGL_debugAssertNoErrors();
2420 void XYWnd_MouseToPoint( XYWnd* xywnd, int x, int y, Vector3& point ){
2421 xywnd->XY_ToPoint( x, y, point );
2422 xywnd->XY_SnapToGrid( point );
2424 int nDim = ( xywnd->GetViewType() == XY ) ? 2 : ( xywnd->GetViewType() == YZ ) ? 0 : 1;
2425 float fWorkMid = float_mid( Select_getWorkZone().d_work_min[nDim], Select_getWorkZone().d_work_max[nDim] );
2426 point[nDim] = float_snapped( fWorkMid, GetGridSize() );
2429 void XYWnd::OnEntityCreate( const char* item ){
2430 StringOutputStream command;
2431 command << "entityCreate -class " << item;
2432 UndoableCommand undo( command.c_str() );
2434 XYWnd_MouseToPoint( this, m_entityCreate_x, m_entityCreate_y, point );
2435 Entity_createFromSelection( item, point );
2440 void GetFocusPosition( Vector3& position ){
2441 if ( GlobalSelectionSystem().countSelected() != 0 ) {
2442 Select_GetMid( position );
2446 position = Camera_getOrigin( *g_pParentWnd->GetCamWnd() );
2450 void XYWnd_Focus( XYWnd* xywnd ){
2452 GetFocusPosition( position );
2453 xywnd->PositionView( position );
2456 void XY_Split_Focus(){
2458 GetFocusPosition( position );
2459 if ( g_pParentWnd->GetXYWnd() ) {
2460 g_pParentWnd->GetXYWnd()->PositionView( position );
2462 if ( g_pParentWnd->GetXZWnd() ) {
2463 g_pParentWnd->GetXZWnd()->PositionView( position );
2465 if ( g_pParentWnd->GetYZWnd() ) {
2466 g_pParentWnd->GetYZWnd()->PositionView( position );
2471 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) {
2472 // cannot do this in a split window
2473 // do something else that the user may want here
2478 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2479 XYWnd_Focus( xywnd );
2483 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) {
2484 // cannot do this in a split window
2485 // do something else that the user may want here
2490 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2491 xywnd->SetViewType( XY );
2492 XYWnd_Focus( xywnd );
2496 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) {
2497 // cannot do this in a split window
2498 // do something else that the user may want here
2503 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2504 xywnd->SetViewType( XZ );
2505 XYWnd_Focus( xywnd );
2509 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) {
2510 // cannot do this in a split window
2511 // do something else that the user may want here
2516 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2517 xywnd->SetViewType( YZ );
2518 XYWnd_Focus( xywnd );
2522 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) {
2523 // cannot do this in a split window
2524 // do something else that the user may want here
2529 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2530 if ( xywnd->GetViewType() == XY ) {
2531 xywnd->SetViewType( XZ );
2533 else if ( xywnd->GetViewType() == XZ ) {
2534 xywnd->SetViewType( YZ );
2537 xywnd->SetViewType( XY );
2539 XYWnd_Focus( xywnd );
2543 if ( g_pParentWnd->GetXYWnd() ) {
2544 g_pParentWnd->GetXYWnd()->SetScale( 1 );
2546 if ( g_pParentWnd->GetXZWnd() ) {
2547 g_pParentWnd->GetXZWnd()->SetScale( 1 );
2549 if ( g_pParentWnd->GetYZWnd() ) {
2550 g_pParentWnd->GetYZWnd()->SetScale( 1 );
2555 g_pParentWnd->ActiveXY()->ZoomIn();
2558 // NOTE: the zoom out factor is 4/5, we could think about customizing it
2559 // we don't go below a zoom factor corresponding to 10% of the max world size
2560 // (this has to be computed against the window size)
2562 g_pParentWnd->ActiveXY()->ZoomOut();
2567 void ToggleShowCrosshair(){
2569 XY_UpdateAllWindows();
2572 void ToggleShowSizeInfo(){
2573 g_xywindow_globals_private.m_bSizePaint = !g_xywindow_globals_private.m_bSizePaint;
2574 XY_UpdateAllWindows();
2577 void ToggleShowGrid(){
2578 g_xywindow_globals_private.d_showgrid = !g_xywindow_globals_private.d_showgrid;
2579 XY_UpdateAllWindows();
2582 ToggleShown g_xy_top_shown( true );
2584 void XY_Top_Shown_Construct( GtkWindow* parent ){
2585 g_xy_top_shown.connect( GTK_WIDGET( parent ) );
2588 ToggleShown g_yz_side_shown( false );
2590 void YZ_Side_Shown_Construct( GtkWindow* parent ){
2591 g_yz_side_shown.connect( GTK_WIDGET( parent ) );
2594 ToggleShown g_xz_front_shown( false );
2596 void XZ_Front_Shown_Construct( GtkWindow* parent ){
2597 g_xz_front_shown.connect( GTK_WIDGET( parent ) );
2601 class EntityClassMenu : public ModuleObserver
2603 std::size_t m_unrealised;
2605 EntityClassMenu() : m_unrealised( 1 ){
2608 if ( --m_unrealised == 0 ) {
2612 if ( ++m_unrealised == 1 ) {
2613 if ( XYWnd::m_mnuDrop != 0 ) {
2614 gtk_widget_destroy( GTK_WIDGET( XYWnd::m_mnuDrop ) );
2615 XYWnd::m_mnuDrop = 0;
2621 EntityClassMenu g_EntityClassMenu;
2626 void ShowNamesToggle(){
2627 GlobalEntityCreator().setShowNames( !GlobalEntityCreator().getShowNames() );
2628 XY_UpdateAllWindows();
2630 typedef FreeCaller<ShowNamesToggle> ShowNamesToggleCaller;
2631 void ShowNamesExport( const BoolImportCallback& importer ){
2632 importer( GlobalEntityCreator().getShowNames() );
2634 typedef FreeCaller1<const BoolImportCallback&, ShowNamesExport> ShowNamesExportCaller;
2636 void ShowAnglesToggle(){
2637 GlobalEntityCreator().setShowAngles( !GlobalEntityCreator().getShowAngles() );
2638 XY_UpdateAllWindows();
2640 typedef FreeCaller<ShowAnglesToggle> ShowAnglesToggleCaller;
2641 void ShowAnglesExport( const BoolImportCallback& importer ){
2642 importer( GlobalEntityCreator().getShowAngles() );
2644 typedef FreeCaller1<const BoolImportCallback&, ShowAnglesExport> ShowAnglesExportCaller;
2646 void ShowBlocksToggle(){
2647 g_xywindow_globals_private.show_blocks ^= 1;
2648 XY_UpdateAllWindows();
2650 typedef FreeCaller<ShowBlocksToggle> ShowBlocksToggleCaller;
2651 void ShowBlocksExport( const BoolImportCallback& importer ){
2652 importer( g_xywindow_globals_private.show_blocks );
2654 typedef FreeCaller1<const BoolImportCallback&, ShowBlocksExport> ShowBlocksExportCaller;
2656 void ShowCoordinatesToggle(){
2657 g_xywindow_globals_private.show_coordinates ^= 1;
2658 XY_UpdateAllWindows();
2660 typedef FreeCaller<ShowCoordinatesToggle> ShowCoordinatesToggleCaller;
2661 void ShowCoordinatesExport( const BoolImportCallback& importer ){
2662 importer( g_xywindow_globals_private.show_coordinates );
2664 typedef FreeCaller1<const BoolImportCallback&, ShowCoordinatesExport> ShowCoordinatesExportCaller;
2666 void ShowOutlineToggle(){
2667 g_xywindow_globals_private.show_outline ^= 1;
2668 XY_UpdateAllWindows();
2670 typedef FreeCaller<ShowOutlineToggle> ShowOutlineToggleCaller;
2671 void ShowOutlineExport( const BoolImportCallback& importer ){
2672 importer( g_xywindow_globals_private.show_outline );
2674 typedef FreeCaller1<const BoolImportCallback&, ShowOutlineExport> ShowOutlineExportCaller;
2676 void ShowAxesToggle(){
2677 g_xywindow_globals_private.show_axis ^= 1;
2678 XY_UpdateAllWindows();
2680 typedef FreeCaller<ShowAxesToggle> ShowAxesToggleCaller;
2681 void ShowAxesExport( const BoolImportCallback& importer ){
2682 importer( g_xywindow_globals_private.show_axis );
2684 typedef FreeCaller1<const BoolImportCallback&, ShowAxesExport> ShowAxesExportCaller;
2686 void ShowWorkzoneToggle(){
2687 g_xywindow_globals_private.d_show_work ^= 1;
2688 XY_UpdateAllWindows();
2690 typedef FreeCaller<ShowWorkzoneToggle> ShowWorkzoneToggleCaller;
2691 void ShowWorkzoneExport( const BoolImportCallback& importer ){
2692 importer( g_xywindow_globals_private.d_show_work );
2694 typedef FreeCaller1<const BoolImportCallback&, ShowWorkzoneExport> ShowWorkzoneExportCaller;
2696 ShowNamesExportCaller g_show_names_caller;
2697 BoolExportCallback g_show_names_callback( g_show_names_caller );
2698 ToggleItem g_show_names( g_show_names_callback );
2700 ShowAnglesExportCaller g_show_angles_caller;
2701 BoolExportCallback g_show_angles_callback( g_show_angles_caller );
2702 ToggleItem g_show_angles( g_show_angles_callback );
2704 ShowBlocksExportCaller g_show_blocks_caller;
2705 BoolExportCallback g_show_blocks_callback( g_show_blocks_caller );
2706 ToggleItem g_show_blocks( g_show_blocks_callback );
2708 ShowCoordinatesExportCaller g_show_coordinates_caller;
2709 BoolExportCallback g_show_coordinates_callback( g_show_coordinates_caller );
2710 ToggleItem g_show_coordinates( g_show_coordinates_callback );
2712 ShowOutlineExportCaller g_show_outline_caller;
2713 BoolExportCallback g_show_outline_callback( g_show_outline_caller );
2714 ToggleItem g_show_outline( g_show_outline_callback );
2716 ShowAxesExportCaller g_show_axes_caller;
2717 BoolExportCallback g_show_axes_callback( g_show_axes_caller );
2718 ToggleItem g_show_axes( g_show_axes_callback );
2720 ShowWorkzoneExportCaller g_show_workzone_caller;
2721 BoolExportCallback g_show_workzone_callback( g_show_workzone_caller );
2722 ToggleItem g_show_workzone( g_show_workzone_callback );
2724 void XYShow_registerCommands(){
2725 GlobalToggles_insert( "ShowAngles", ShowAnglesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_angles ) );
2726 GlobalToggles_insert( "ShowNames", ShowNamesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_names ) );
2727 GlobalToggles_insert( "ShowBlocks", ShowBlocksToggleCaller(), ToggleItem::AddCallbackCaller( g_show_blocks ) );
2728 GlobalToggles_insert( "ShowCoordinates", ShowCoordinatesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_coordinates ) );
2729 GlobalToggles_insert( "ShowWindowOutline", ShowOutlineToggleCaller(), ToggleItem::AddCallbackCaller( g_show_outline ) );
2730 GlobalToggles_insert( "ShowAxes", ShowAxesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_axes ) );
2731 GlobalToggles_insert( "ShowWorkzone", ShowWorkzoneToggleCaller(), ToggleItem::AddCallbackCaller( g_show_workzone ) );
2734 void XYWnd_registerShortcuts(){
2735 command_connect_accelerator( "ToggleCrosshairs" );
2736 command_connect_accelerator( "ToggleSizePaint" );
2741 void Orthographic_constructPreferences( PreferencesPage& page ){
2742 page.appendCheckBox( "", "Solid selection boxes", g_xywindow_globals.m_bNoStipple );
2743 page.appendCheckBox( "", "Display size info", g_xywindow_globals_private.m_bSizePaint );
2744 page.appendCheckBox( "", "Chase mouse during drags", g_xywindow_globals_private.m_bChaseMouse );
2745 page.appendCheckBox( "", "Update views on camera move", g_xywindow_globals_private.m_bCamXYUpdate );
2747 void Orthographic_constructPage( PreferenceGroup& group ){
2748 PreferencesPage page( group.createPage( "Orthographic", "Orthographic View Preferences" ) );
2749 Orthographic_constructPreferences( page );
2751 void Orthographic_registerPreferencesPage(){
2752 PreferencesDialog_addSettingsPage( FreeCaller1<PreferenceGroup&, Orthographic_constructPage>() );
2755 void Clipper_constructPreferences( PreferencesPage& page ){
2756 page.appendCheckBox( "", "Clipper tool uses caulk", g_clip_useCaulk );
2758 void Clipper_constructPage( PreferenceGroup& group ){
2759 PreferencesPage page( group.createPage( "Clipper", "Clipper Tool Settings" ) );
2760 Clipper_constructPreferences( page );
2762 void Clipper_registerPreferencesPage(){
2763 PreferencesDialog_addSettingsPage( FreeCaller1<PreferenceGroup&, Clipper_constructPage>() );
2767 #include "preferencesystem.h"
2768 #include "stringio.h"
2773 void ToggleShown_importBool( ToggleShown& self, bool value ){
2776 typedef ReferenceCaller1<ToggleShown, bool, ToggleShown_importBool> ToggleShownImportBoolCaller;
2777 void ToggleShown_exportBool( const ToggleShown& self, const BoolImportCallback& importer ){
2778 importer( self.active() );
2780 typedef ConstReferenceCaller1<ToggleShown, const BoolImportCallback&, ToggleShown_exportBool> ToggleShownExportBoolCaller;
2783 void XYWindow_Construct(){
2784 GlobalCommands_insert( "ToggleCrosshairs", FreeCaller<ToggleShowCrosshair>(), Accelerator( 'X', (GdkModifierType)GDK_SHIFT_MASK ) );
2785 GlobalCommands_insert( "ToggleSizePaint", FreeCaller<ToggleShowSizeInfo>(), Accelerator( 'J' ) );
2786 GlobalCommands_insert( "ToggleGrid", FreeCaller<ToggleShowGrid>(), Accelerator( '0' ) );
2788 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 ) ) );
2789 GlobalToggles_insert( "ToggleSideView", ToggleShown::ToggleCaller( g_yz_side_shown ), ToggleItem::AddCallbackCaller( g_yz_side_shown.m_item ) );
2790 GlobalToggles_insert( "ToggleFrontView", ToggleShown::ToggleCaller( g_xz_front_shown ), ToggleItem::AddCallbackCaller( g_xz_front_shown.m_item ) );
2791 GlobalCommands_insert( "NextView", FreeCaller<XY_Next>(), Accelerator( GDK_Tab, (GdkModifierType)GDK_CONTROL_MASK ) );
2792 GlobalCommands_insert( "ZoomIn", FreeCaller<XY_ZoomIn>(), Accelerator( GDK_Delete ) );
2793 GlobalCommands_insert( "ZoomOut", FreeCaller<XY_ZoomOut>(), Accelerator( GDK_Insert ) );
2794 GlobalCommands_insert( "ViewTop", FreeCaller<XY_Top>(), Accelerator( GDK_KP_Home ) );
2795 GlobalCommands_insert( "ViewSide", FreeCaller<XY_Side>(), Accelerator( GDK_KP_Page_Down ) );
2796 GlobalCommands_insert( "ViewFront", FreeCaller<XY_Front>(), Accelerator( GDK_KP_End ) );
2797 GlobalCommands_insert( "Zoom100", FreeCaller<XY_Zoom100>() );
2798 GlobalCommands_insert( "CenterXYView", FreeCaller<XY_Focus>(), Accelerator( GDK_Tab, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
2800 GlobalPreferenceSystem().registerPreference( "ClipCaulk", BoolImportStringCaller( g_clip_useCaulk ), BoolExportStringCaller( g_clip_useCaulk ) );
2802 GlobalPreferenceSystem().registerPreference( "NewRightClick", BoolImportStringCaller( g_xywindow_globals.m_bRightClick ), BoolExportStringCaller( g_xywindow_globals.m_bRightClick ) );
2803 GlobalPreferenceSystem().registerPreference( "ImprovedWheelZoom", BoolImportStringCaller( g_xywindow_globals.m_bImprovedWheelZoom ), BoolExportStringCaller( g_xywindow_globals.m_bImprovedWheelZoom ) );
2804 GlobalPreferenceSystem().registerPreference( "ChaseMouse", BoolImportStringCaller( g_xywindow_globals_private.m_bChaseMouse ), BoolExportStringCaller( g_xywindow_globals_private.m_bChaseMouse ) );
2805 GlobalPreferenceSystem().registerPreference( "SizePainting", BoolImportStringCaller( g_xywindow_globals_private.m_bSizePaint ), BoolExportStringCaller( g_xywindow_globals_private.m_bSizePaint ) );
2806 GlobalPreferenceSystem().registerPreference( "ShowCrosshair", BoolImportStringCaller( g_bCrossHairs ), BoolExportStringCaller( g_bCrossHairs ) );
2807 GlobalPreferenceSystem().registerPreference( "NoStipple", BoolImportStringCaller( g_xywindow_globals.m_bNoStipple ), BoolExportStringCaller( g_xywindow_globals.m_bNoStipple ) );
2808 GlobalPreferenceSystem().registerPreference( "SI_ShowCoords", BoolImportStringCaller( g_xywindow_globals_private.show_coordinates ), BoolExportStringCaller( g_xywindow_globals_private.show_coordinates ) );
2809 GlobalPreferenceSystem().registerPreference( "SI_ShowOutlines", BoolImportStringCaller( g_xywindow_globals_private.show_outline ), BoolExportStringCaller( g_xywindow_globals_private.show_outline ) );
2810 GlobalPreferenceSystem().registerPreference( "SI_ShowAxis", BoolImportStringCaller( g_xywindow_globals_private.show_axis ), BoolExportStringCaller( g_xywindow_globals_private.show_axis ) );
2811 GlobalPreferenceSystem().registerPreference( "CamXYUpdate", BoolImportStringCaller( g_xywindow_globals_private.m_bCamXYUpdate ), BoolExportStringCaller( g_xywindow_globals_private.m_bCamXYUpdate ) );
2812 GlobalPreferenceSystem().registerPreference( "ShowWorkzone", BoolImportStringCaller( g_xywindow_globals_private.d_show_work ), BoolExportStringCaller( g_xywindow_globals_private.d_show_work ) );
2814 GlobalPreferenceSystem().registerPreference( "SI_AxisColors0", Vector3ImportStringCaller( g_xywindow_globals.AxisColorX ), Vector3ExportStringCaller( g_xywindow_globals.AxisColorX ) );
2815 GlobalPreferenceSystem().registerPreference( "SI_AxisColors1", Vector3ImportStringCaller( g_xywindow_globals.AxisColorY ), Vector3ExportStringCaller( g_xywindow_globals.AxisColorY ) );
2816 GlobalPreferenceSystem().registerPreference( "SI_AxisColors2", Vector3ImportStringCaller( g_xywindow_globals.AxisColorZ ), Vector3ExportStringCaller( g_xywindow_globals.AxisColorZ ) );
2817 GlobalPreferenceSystem().registerPreference( "SI_Colors1", Vector3ImportStringCaller( g_xywindow_globals.color_gridback ), Vector3ExportStringCaller( g_xywindow_globals.color_gridback ) );
2818 GlobalPreferenceSystem().registerPreference( "SI_Colors2", Vector3ImportStringCaller( g_xywindow_globals.color_gridminor ), Vector3ExportStringCaller( g_xywindow_globals.color_gridminor ) );
2819 GlobalPreferenceSystem().registerPreference( "SI_Colors3", Vector3ImportStringCaller( g_xywindow_globals.color_gridmajor ), Vector3ExportStringCaller( g_xywindow_globals.color_gridmajor ) );
2820 GlobalPreferenceSystem().registerPreference( "SI_Colors6", Vector3ImportStringCaller( g_xywindow_globals.color_gridblock ), Vector3ExportStringCaller( g_xywindow_globals.color_gridblock ) );
2821 GlobalPreferenceSystem().registerPreference( "SI_Colors7", Vector3ImportStringCaller( g_xywindow_globals.color_gridtext ), Vector3ExportStringCaller( g_xywindow_globals.color_gridtext ) );
2822 GlobalPreferenceSystem().registerPreference( "SI_Colors8", Vector3ImportStringCaller( g_xywindow_globals.color_brushes ), Vector3ExportStringCaller( g_xywindow_globals.color_brushes ) );
2823 GlobalPreferenceSystem().registerPreference( "SI_Colors14", Vector3ImportStringCaller( g_xywindow_globals.color_gridmajor_alt ), Vector3ExportStringCaller( g_xywindow_globals.color_gridmajor_alt ) );
2826 GlobalPreferenceSystem().registerPreference( "XZVIS", makeBoolStringImportCallback( ToggleShownImportBoolCaller( g_xz_front_shown ) ), makeBoolStringExportCallback( ToggleShownExportBoolCaller( g_xz_front_shown ) ) );
2827 GlobalPreferenceSystem().registerPreference( "YZVIS", makeBoolStringImportCallback( ToggleShownImportBoolCaller( g_yz_side_shown ) ), makeBoolStringExportCallback( ToggleShownExportBoolCaller( g_yz_side_shown ) ) );
2829 Orthographic_registerPreferencesPage();
2830 Clipper_registerPreferencesPage();
2832 XYWnd::captureStates();
2833 GlobalEntityClassManager().attach( g_EntityClassMenu );
2836 void XYWindow_Destroy(){
2837 GlobalEntityClassManager().detach( g_EntityClassMenu );
2838 XYWnd::releaseStates();