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"
64 #include "brushmanip.h"
65 #include "selection.h"
67 #include "camwindow.h"
68 #include "texwindow.h"
69 #include "mainframe.h"
70 #include "preferences.h"
74 #include "windowobservers.h"
76 void LoadTextureRGBA( qtexture_t* q, unsigned char* pPixels, int nWidth, int nHeight );
79 extern bool g_brush_always_caulk;
85 Vector3 m_ptClip; // the 3d point
92 m_ptClip[0] = m_ptClip[1] = m_ptClip[2] = 0.0;
106 /*! Draw clip/path point with rasterized number label */
107 void Draw( int num, float scale );
108 /*! Draw clip/path point with rasterized string label */
109 void Draw( const char *label, float scale );
112 VIEWTYPE g_clip_viewtype;
113 bool g_bSwitch = true;
114 bool g_clip_useCaulk = false;
118 ClipPoint* g_pMovingClip = 0;
120 /* Drawing clip points */
121 void ClipPoint::Draw( int num, float scale ){
122 StringOutputStream label( 4 );
124 Draw( label.c_str(), scale );
127 void ClipPoint::Draw( const char *label, float scale ){
130 glColor3fv( vector3_to_array( g_xywindow_globals.color_clipper ) );
131 glBegin( GL_POINTS );
132 glVertex3fv( vector3_to_array( m_ptClip ) );
136 float offset = 2.0f / scale;
139 glRasterPos3f( m_ptClip[0] + offset, m_ptClip[1] + offset, m_ptClip[2] + offset );
140 glCallLists( GLsizei( strlen( label ) ), GL_UNSIGNED_BYTE, label );
143 float fDiff( float f1, float f2 ){
152 inline double ClipPoint_Intersect( const ClipPoint& clip, const Vector3& point, VIEWTYPE viewtype, float scale ){
153 int nDim1 = ( viewtype == YZ ) ? 1 : 0;
154 int nDim2 = ( viewtype == XY ) ? 1 : 2;
155 double screenDistanceSquared( vector2_length_squared( Vector2( fDiff( clip.m_ptClip[nDim1], point[nDim1] ) * scale, fDiff( clip.m_ptClip[nDim2], point[nDim2] ) * scale ) ) );
156 if ( screenDistanceSquared < 8 * 8 ) {
157 return screenDistanceSquared;
162 inline void ClipPoint_testSelect( ClipPoint& clip, const Vector3& point, VIEWTYPE viewtype, float scale, double& bestDistance, ClipPoint*& bestClip ){
164 double distance = ClipPoint_Intersect( clip, point, viewtype, scale );
165 if ( distance < bestDistance ) {
166 bestDistance = distance;
172 inline ClipPoint* GlobalClipPoints_Find( const Vector3& point, VIEWTYPE viewtype, float scale ){
173 double bestDistance = FLT_MAX;
174 ClipPoint* bestClip = 0;
175 ClipPoint_testSelect( g_Clip1, point, viewtype, scale, bestDistance, bestClip );
176 ClipPoint_testSelect( g_Clip2, point, viewtype, scale, bestDistance, bestClip );
177 ClipPoint_testSelect( g_Clip3, point, viewtype, scale, bestDistance, bestClip );
181 inline void GlobalClipPoints_Draw( float scale ){
183 if ( g_Clip1.Set() ) {
184 g_Clip1.Draw( 1, scale );
186 if ( g_Clip2.Set() ) {
187 g_Clip2.Draw( 2, scale );
189 if ( g_Clip3.Set() ) {
190 g_Clip3.Draw( 3, scale );
194 inline bool GlobalClipPoints_valid(){
195 return g_Clip1.Set() && g_Clip2.Set();
198 void PlanePointsFromClipPoints( Vector3 planepts[3], const AABB& bounds, int viewtype ){
199 ASSERT_MESSAGE( GlobalClipPoints_valid(), "clipper points not initialised" );
200 planepts[0] = g_Clip1.m_ptClip;
201 planepts[1] = g_Clip2.m_ptClip;
202 planepts[2] = g_Clip3.m_ptClip;
203 Vector3 maxs( vector3_added( bounds.origin, bounds.extents ) );
204 Vector3 mins( vector3_subtracted( bounds.origin, bounds.extents ) );
205 if ( !g_Clip3.Set() ) {
206 int n = ( viewtype == XY ) ? 2 : ( viewtype == YZ ) ? 0 : 1;
207 int x = ( n == 0 ) ? 1 : 0;
208 int y = ( n == 2 ) ? 1 : 2;
210 if ( n == 1 ) { // on viewtype XZ, flip clip points
211 planepts[0][n] = maxs[n];
212 planepts[1][n] = maxs[n];
213 planepts[2][x] = g_Clip1.m_ptClip[x];
214 planepts[2][y] = g_Clip1.m_ptClip[y];
215 planepts[2][n] = mins[n];
219 planepts[0][n] = mins[n];
220 planepts[1][n] = mins[n];
221 planepts[2][x] = g_Clip1.m_ptClip[x];
222 planepts[2][y] = g_Clip1.m_ptClip[y];
223 planepts[2][n] = maxs[n];
230 if ( !GlobalClipPoints_valid() ) {
231 planepts[0] = Vector3( 0, 0, 0 );
232 planepts[1] = Vector3( 0, 0, 0 );
233 planepts[2] = Vector3( 0, 0, 0 );
234 Scene_BrushSetClipPlane( GlobalSceneGraph(), Plane3( 0, 0, 0, 0 ) );
238 AABB bounds( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) );
239 PlanePointsFromClipPoints( planepts, bounds, g_clip_viewtype );
241 std::swap( planepts[0], planepts[1] );
243 Scene_BrushSetClipPlane( GlobalSceneGraph(), plane3_for_points( planepts[0], planepts[1], planepts[2] ) );
245 ClipperChangeNotify();
248 const char* Clip_getShader(){
249 return g_clip_useCaulk ? "textures/common/caulk" : TextureBrowser_GetSelectedShader( GlobalTextureBrowser() );
253 if ( ClipMode() && GlobalClipPoints_valid() ) {
255 AABB bounds( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) );
256 PlanePointsFromClipPoints( planepts, bounds, g_clip_viewtype );
257 Scene_BrushSplitByPlane( GlobalSceneGraph(), planepts[0], planepts[1], planepts[2], Clip_getShader(), ( !g_bSwitch ) ? eFront : eBack );
262 ClipperChangeNotify();
267 if ( ClipMode() && GlobalClipPoints_valid() ) {
269 AABB bounds( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) );
270 PlanePointsFromClipPoints( planepts, bounds, g_clip_viewtype );
271 Scene_BrushSplitByPlane( GlobalSceneGraph(), planepts[0], planepts[1], planepts[2], Clip_getShader(), eFrontAndBack );
276 ClipperChangeNotify();
281 g_bSwitch = !g_bSwitch;
283 ClipperChangeNotify();
286 void OnClipMode( bool enabled ){
291 if ( !enabled && g_pMovingClip ) {
296 ClipperChangeNotify();
300 return GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eClip;
303 void NewClipPoint( const Vector3& point ){
304 if ( g_Clip1.Set() == false ) {
305 g_Clip1.m_ptClip = point;
308 else if ( g_Clip2.Set() == false ) {
309 g_Clip2.m_ptClip = point;
312 else if ( g_Clip3.Set() == false ) {
313 g_Clip3.m_ptClip = point;
321 g_Clip1.m_ptClip = point;
326 ClipperChangeNotify();
331 struct xywindow_globals_private_t
335 // these are in the View > Show menu with Show coordinates
337 bool show_coordinates;
353 xywindow_globals_private_t() :
357 show_coordinates( true ),
359 show_outline( false ),
362 d_show_work( false ),
364 show_blocks( false ),
366 m_bCamXYUpdate( true ),
367 m_bChaseMouse( true ),
368 m_bSizePaint( true ),
370 g_bCrossHairs( false ){
375 xywindow_globals_t g_xywindow_globals;
376 xywindow_globals_private_t g_xywindow_globals_private;
378 const unsigned int RAD_NONE = 0x00;
379 const unsigned int RAD_SHIFT = 0x01;
380 const unsigned int RAD_ALT = 0x02;
381 const unsigned int RAD_CONTROL = 0x04;
382 const unsigned int RAD_PRESS = 0x08;
383 const unsigned int RAD_LBUTTON = 0x10;
384 const unsigned int RAD_MBUTTON = 0x20;
385 const unsigned int RAD_RBUTTON = 0x40;
387 inline ButtonIdentifier button_for_flags( unsigned int flags ){
388 if ( flags & RAD_LBUTTON ) {
391 if ( flags & RAD_RBUTTON ) {
392 return c_buttonRight;
394 if ( flags & RAD_MBUTTON ) {
395 return c_buttonMiddle;
397 return c_buttonInvalid;
400 inline ModifierFlags modifiers_for_flags( unsigned int flags ){
401 ModifierFlags modifiers = c_modifierNone;
402 if ( flags & RAD_SHIFT ) {
403 modifiers |= c_modifierShift;
405 if ( flags & RAD_CONTROL ) {
406 modifiers |= c_modifierControl;
408 if ( flags & RAD_ALT ) {
409 modifiers |= c_modifierAlt;
414 inline unsigned int buttons_for_button_and_modifiers( ButtonIdentifier button, ModifierFlags flags ){
415 unsigned int buttons = 0;
417 switch ( button.get() )
419 case ButtonEnumeration::INVALID: break;
420 case ButtonEnumeration::LEFT: buttons |= RAD_LBUTTON; break;
421 case ButtonEnumeration::MIDDLE: buttons |= RAD_MBUTTON; break;
422 case ButtonEnumeration::RIGHT: buttons |= RAD_RBUTTON; break;
425 if ( bitfield_enabled( flags, c_modifierControl ) ) {
426 buttons |= RAD_CONTROL;
429 if ( bitfield_enabled( flags, c_modifierShift ) ) {
430 buttons |= RAD_SHIFT;
433 if ( bitfield_enabled( flags, c_modifierAlt ) ) {
440 inline unsigned int buttons_for_event_button( GdkEventButton* event ){
441 unsigned int flags = 0;
443 switch ( event->button )
445 case 1: flags |= RAD_LBUTTON; break;
446 case 2: flags |= RAD_MBUTTON; break;
447 case 3: flags |= RAD_RBUTTON; break;
450 if ( ( event->state & GDK_CONTROL_MASK ) != 0 ) {
451 flags |= RAD_CONTROL;
454 if ( ( event->state & GDK_SHIFT_MASK ) != 0 ) {
458 if ( ( event->state & GDK_MOD1_MASK ) != 0 ) {
465 inline unsigned int buttons_for_state( guint state ){
466 unsigned int flags = 0;
468 if ( ( state & GDK_BUTTON1_MASK ) != 0 ) {
469 flags |= RAD_LBUTTON;
472 if ( ( state & GDK_BUTTON2_MASK ) != 0 ) {
473 flags |= RAD_MBUTTON;
476 if ( ( state & GDK_BUTTON3_MASK ) != 0 ) {
477 flags |= RAD_RBUTTON;
480 if ( ( state & GDK_CONTROL_MASK ) != 0 ) {
481 flags |= RAD_CONTROL;
484 if ( ( state & GDK_SHIFT_MASK ) != 0 ) {
488 if ( ( state & GDK_MOD1_MASK ) != 0 ) {
496 void XYWnd::SetScale( float f ){
500 XYWnd_Update( *this );
503 void XYWnd::ZoomIn(){
504 float max_scale = 64;
505 float scale = Scale() * 5.0f / 4.0f;
506 if ( scale > max_scale ) {
507 if ( Scale() != max_scale ) {
508 SetScale( max_scale );
518 // NOTE: the zoom out factor is 4/5, we could think about customizing it
519 // we don't go below a zoom factor corresponding to 10% of the max world size
520 // (this has to be computed against the window size)
521 void XYWnd::ZoomOut(){
522 float min_scale = MIN( Width(), Height() ) / ( 1.1f * ( g_MaxWorldCoord - g_MinWorldCoord ) );
523 float scale = Scale() * 4.0f / 5.0f;
524 if ( scale < min_scale ) {
525 if ( Scale() != min_scale ) {
526 SetScale( min_scale );
535 void XYWnd::ZoomInWithMouse( int pointx, int pointy ){
536 float old_scale = Scale();
538 if ( g_xywindow_globals.m_bImprovedWheelZoom ) {
539 float scale_diff = 1.0 / old_scale - 1.0 / Scale();
540 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
541 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
542 Vector3 origin = GetOrigin();
543 origin[nDim1] += scale_diff * (pointx - 0.5 * Width());
544 origin[nDim2] -= scale_diff * (pointy - 0.5 * Height());
549 VIEWTYPE GlobalXYWnd_getCurrentViewType(){
550 ASSERT_NOTNULL( g_pParentWnd );
551 ASSERT_NOTNULL( g_pParentWnd->ActiveXY() );
552 return g_pParentWnd->ActiveXY()->GetViewType();
555 // =============================================================================
558 ui::Menu XYWnd::m_mnuDrop(ui::null);
560 // this is disabled, and broken
561 // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=394
565 width = g_pParentWnd->ActiveXY()->Width();
566 height = g_pParentWnd->ActiveXY()->Height();
568 const char* filename;
570 filename = ui::file_dialog( MainFrame_getWindow( ), FALSE, "Save Image", 0, FILTER_BMP );
575 g_pParentWnd->ActiveXY()->MakeCurrent();
576 img = (unsigned char*)malloc( width * height * 3 );
577 glReadPixels( 0,0,width,height,GL_RGB,GL_UNSIGNED_BYTE,img );
580 fp = fopen( filename, "wb" );
583 unsigned long cmap, bfSize;
587 bfSize = 54 + width * height * 3;
589 long byteswritten = 0;
590 long pixoff = 54 + cmap * 4;
592 char m1 = 'B', m2 = 'M';
593 fwrite( &m1, 1, 1, fp ); byteswritten++; // B
594 fwrite( &m2, 1, 1, fp ); byteswritten++; // M
595 fwrite( &bfSize, 4, 1, fp ); byteswritten += 4; // bfSize
596 fwrite( &res, 2, 1, fp ); byteswritten += 2; // bfReserved1
597 fwrite( &res, 2, 1, fp ); byteswritten += 2; // bfReserved2
598 fwrite( &pixoff, 4, 1, fp ); byteswritten += 4; // bfOffBits
600 unsigned long biSize = 40, compress = 0, size = 0;
602 unsigned short planes = 1;
603 fwrite( &biSize, 4, 1, fp ); byteswritten += 4; // biSize
604 fwrite( &width, 4, 1, fp ); byteswritten += 4; // biWidth
605 fwrite( &height, 4, 1, fp ); byteswritten += 4; // biHeight
606 fwrite( &planes, 2, 1, fp ); byteswritten += 2; // biPlanes
607 fwrite( &bits, 2, 1, fp ); byteswritten += 2; // biBitCount
608 fwrite( &compress, 4, 1, fp ); byteswritten += 4; // biCompression
609 fwrite( &size, 4, 1, fp ); byteswritten += 4; // biSizeImage
610 fwrite( &pixels, 4, 1, fp ); byteswritten += 4; // biXPelsPerMeter
611 fwrite( &pixels, 4, 1, fp ); byteswritten += 4; // biYPelsPerMeter
612 fwrite( &cmap, 4, 1, fp ); byteswritten += 4; // biClrUsed
613 fwrite( &cmap, 4, 1, fp ); byteswritten += 4; // biClrImportant
615 unsigned long widthDW = ( ( ( width * 24 ) + 31 ) / 32 * 4 );
616 long row, row_size = width * 3;
617 for ( row = 0; row < height; row++ )
619 unsigned char* buf = img + row * row_size;
623 for ( col = 0; col < row_size; col += 3 )
625 putc( buf[col + 2], fp );
626 putc( buf[col + 1], fp );
627 putc( buf[col], fp );
629 byteswritten += row_size;
632 for ( count = row_size; count < widthDW; count++ )
634 putc( 0, fp ); // dummy
649 Timer g_chasemouse_timer;
651 void XYWnd::ChaseMouse(){
652 float multiplier = g_chasemouse_timer.elapsed_msec() / 10.0f;
653 Scroll( float_to_integer( multiplier * m_chasemouse_delta_x ), float_to_integer( multiplier * -m_chasemouse_delta_y ) );
655 //globalOutputStream() << "chasemouse: multiplier=" << multiplier << " x=" << m_chasemouse_delta_x << " y=" << m_chasemouse_delta_y << '\n';
657 XY_MouseMoved( m_chasemouse_current_x, m_chasemouse_current_y, getButtonState() );
658 g_chasemouse_timer.start();
661 gboolean xywnd_chasemouse( gpointer data ){
662 reinterpret_cast<XYWnd*>( data )->ChaseMouse();
666 inline const int& min_int( const int& left, const int& right ){
667 return std::min( left, right );
670 bool XYWnd::chaseMouseMotion( int pointx, int pointy ){
671 m_chasemouse_delta_x = 0;
672 m_chasemouse_delta_y = 0;
674 if ( g_xywindow_globals_private.m_bChaseMouse && getButtonState() == RAD_LBUTTON ) {
675 const int epsilon = 16;
677 if ( pointx < epsilon ) {
678 m_chasemouse_delta_x = std::max( pointx, 0 ) - epsilon;
680 else if ( ( pointx - m_nWidth ) > -epsilon ) {
681 m_chasemouse_delta_x = min_int( ( pointx - m_nWidth ), 0 ) + epsilon;
684 if ( pointy < epsilon ) {
685 m_chasemouse_delta_y = std::max( pointy, 0 ) - epsilon;
687 else if ( ( pointy - m_nHeight ) > -epsilon ) {
688 m_chasemouse_delta_y = min_int( ( pointy - m_nHeight ), 0 ) + epsilon;
691 if ( m_chasemouse_delta_y != 0 || m_chasemouse_delta_x != 0 ) {
692 //globalOutputStream() << "chasemouse motion: x=" << pointx << " y=" << pointy << "... ";
693 m_chasemouse_current_x = pointx;
694 m_chasemouse_current_y = pointy;
695 if ( m_chasemouse_handler == 0 ) {
696 //globalOutputStream() << "chasemouse timer start... ";
697 g_chasemouse_timer.start();
698 m_chasemouse_handler = g_idle_add( xywnd_chasemouse, this );
704 if ( m_chasemouse_handler != 0 ) {
705 //globalOutputStream() << "chasemouse cancel\n";
706 g_source_remove( m_chasemouse_handler );
707 m_chasemouse_handler = 0;
713 if ( m_chasemouse_handler != 0 ) {
714 //globalOutputStream() << "chasemouse cancel\n";
715 g_source_remove( m_chasemouse_handler );
716 m_chasemouse_handler = 0;
722 // =============================================================================
724 Shader* XYWnd::m_state_selected = 0;
726 void xy_update_xor_rectangle( XYWnd& self, rect_t area ){
727 if ( self.GetWidget().visible() ) {
728 rectangle_t rect = rectangle_from_area( area.min, area.max, self.Width(), self.Height() );
729 int nDim1 = ( self.GetViewType() == YZ ) ? 1 : 0;
730 int nDim2 = ( self.GetViewType() == XY ) ? 1 : 2;
731 rect.x /= self.Scale();
732 rect.y /= self.Scale();
733 rect.w /= self.Scale();
734 rect.h /= self.Scale();
735 rect.x += self.GetOrigin()[nDim1];
736 rect.y += self.GetOrigin()[nDim2];
737 self.m_XORRectangle.set( rect );
741 gboolean xywnd_button_press( ui::Widget widget, GdkEventButton* event, XYWnd* xywnd ){
742 if ( event->type == GDK_BUTTON_PRESS ) {
743 g_pParentWnd->SetActiveXY( xywnd );
745 xywnd->ButtonState_onMouseDown( buttons_for_event_button( event ) );
747 xywnd->onMouseDown( WindowVector( event->x, event->y ), button_for_button( event->button ), modifiers_for_state( event->state ) );
752 gboolean xywnd_button_release( ui::Widget widget, GdkEventButton* event, XYWnd* xywnd ){
753 if ( event->type == GDK_BUTTON_RELEASE ) {
754 xywnd->XY_MouseUp( static_cast<int>( event->x ), static_cast<int>( event->y ), buttons_for_event_button( event ) );
756 xywnd->ButtonState_onMouseUp( buttons_for_event_button( event ) );
761 gboolean xywnd_focus_in( ui::Widget widget, GdkEventFocus* event, XYWnd* xywnd ){
762 if ( event->type == GDK_FOCUS_CHANGE ) {
764 g_pParentWnd->SetActiveXY( xywnd );
770 void xywnd_motion( gdouble x, gdouble y, guint state, void* data ){
771 if ( reinterpret_cast<XYWnd*>( data )->chaseMouseMotion( static_cast<int>( x ), static_cast<int>( y ) ) ) {
774 reinterpret_cast<XYWnd*>( data )->XY_MouseMoved( static_cast<int>( x ), static_cast<int>( y ), buttons_for_state( state ) );
777 gboolean xywnd_wheel_scroll( ui::Widget widget, GdkEventScroll* event, XYWnd* xywnd ){
778 if ( event->direction == GDK_SCROLL_UP ) {
779 xywnd->ZoomInWithMouse( (int)event->x, (int)event->y );
781 else if ( event->direction == GDK_SCROLL_DOWN ) {
787 gboolean xywnd_size_allocate( ui::Widget widget, GtkAllocation* allocation, XYWnd* xywnd ){
788 xywnd->m_nWidth = allocation->width;
789 xywnd->m_nHeight = allocation->height;
790 xywnd->updateProjection();
791 xywnd->m_window_observer->onSizeChanged( xywnd->Width(), xywnd->Height() );
795 gboolean xywnd_expose( ui::Widget widget, GdkEventExpose* event, XYWnd* xywnd ){
796 if ( glwidget_make_current( xywnd->GetWidget() ) != FALSE ) {
797 if ( Map_Valid( g_map ) && ScreenUpdates_Enabled() ) {
798 GlobalOpenGL_debugAssertNoErrors();
800 GlobalOpenGL_debugAssertNoErrors();
802 xywnd->m_XORRectangle.set( rectangle_t() );
804 glwidget_swap_buffers( xywnd->GetWidget() );
810 void XYWnd_CameraMoved( XYWnd& xywnd ){
811 if ( g_xywindow_globals_private.m_bCamXYUpdate ) {
812 XYWnd_Update( xywnd );
817 m_gl_widget( glwidget_new( FALSE ) ),
818 m_deferredDraw( WidgetQueueDrawCaller( m_gl_widget ) ),
819 m_deferred_motion( xywnd_motion, this ),
820 m_parent( ui::null ),
821 m_window_observer( NewWindowObserver() ),
822 m_XORRectangle( m_gl_widget ),
823 m_chasemouse_handler( 0 ){
827 m_bNewBrushDrag = false;
828 m_move_started = false;
829 m_zoom_started = false;
840 m_backgroundActivated = false;
847 m_entityCreate = false;
849 m_mnuDrop = ui::Menu(ui::null);
851 GlobalWindowObservers_add( m_window_observer );
852 GlobalWindowObservers_connectWidget( m_gl_widget );
854 m_window_observer->setRectangleDrawCallback( ReferenceCaller<XYWnd, void(rect_t), xy_update_xor_rectangle>( *this ) );
855 m_window_observer->setView( m_view );
857 g_object_ref( m_gl_widget._handle );
859 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 );
860 gtk_widget_set_can_focus( m_gl_widget, true );
862 m_sizeHandler = m_gl_widget.connect( "size_allocate", G_CALLBACK( xywnd_size_allocate ), this );
863 m_exposeHandler = m_gl_widget.on_render( G_CALLBACK( xywnd_expose ), this );
865 m_gl_widget.connect( "button_press_event", G_CALLBACK( xywnd_button_press ), this );
866 m_gl_widget.connect( "button_release_event", G_CALLBACK( xywnd_button_release ), this );
867 m_gl_widget.connect( "focus_in_event", G_CALLBACK( xywnd_focus_in ), this );
868 m_gl_widget.connect( "motion_notify_event", G_CALLBACK( DeferredMotion::gtk_motion ), &m_deferred_motion );
870 m_gl_widget.connect( "scroll_event", G_CALLBACK( xywnd_wheel_scroll ), this );
872 Map_addValidCallback( g_map, DeferredDrawOnMapValidChangedCaller( m_deferredDraw ) );
877 AddSceneChangeCallback( ReferenceCaller<XYWnd, void(), &XYWnd_Update>( *this ) );
878 AddCameraMovedCallback( ReferenceCaller<XYWnd, void(), &XYWnd_CameraMoved>( *this ) );
880 PressedButtons_connect( g_pressedButtons, m_gl_widget );
882 onMouseDown.connectLast( makeSignalHandler3( MouseDownCaller(), *this ) );
890 m_mnuDrop = ui::Menu(ui::null);
893 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_sizeHandler );
894 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_exposeHandler );
898 m_window_observer->release();
901 void XYWnd::captureStates(){
902 m_state_selected = GlobalShaderCache().capture( "$XY_OVERLAY" );
905 void XYWnd::releaseStates(){
906 GlobalShaderCache().release( "$XY_OVERLAY" );
909 const Vector3& XYWnd::GetOrigin(){
913 void XYWnd::SetOrigin( const Vector3& origin ){
918 void XYWnd::Scroll( int x, int y ){
919 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
920 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
921 m_vOrigin[nDim1] += x / m_fScale;
922 m_vOrigin[nDim2] += y / m_fScale;
927 unsigned int Clipper_buttons(){
931 void XYWnd::DropClipPoint( int pointx, int pointy ){
934 XY_ToPoint( pointx, pointy, point );
937 Select_GetMid( mid );
938 g_clip_viewtype = static_cast<VIEWTYPE>( GetViewType() );
939 const int nDim = ( g_clip_viewtype == YZ ) ? 0 : ( ( g_clip_viewtype == XZ ) ? 1 : 2 );
940 point[nDim] = mid[nDim];
941 vector3_snap( point, GetSnapGridSize() );
942 NewClipPoint( point );
945 void XYWnd::Clipper_OnLButtonDown( int x, int y ){
946 Vector3 mousePosition;
947 XY_ToPoint( x, y, mousePosition );
948 g_pMovingClip = GlobalClipPoints_Find( mousePosition, (VIEWTYPE)m_viewType, m_fScale );
949 if ( !g_pMovingClip ) {
950 DropClipPoint( x, y );
954 void XYWnd::Clipper_OnLButtonUp( int x, int y ){
955 if ( g_pMovingClip ) {
960 void XYWnd::Clipper_OnMouseMoved( int x, int y ){
961 if ( g_pMovingClip ) {
962 XY_ToPoint( x, y, g_pMovingClip->m_ptClip );
963 XY_SnapToGrid( g_pMovingClip->m_ptClip );
965 ClipperChangeNotify();
969 void XYWnd::Clipper_Crosshair_OnMouseMoved( int x, int y ){
970 Vector3 mousePosition;
971 XY_ToPoint( x, y, mousePosition );
972 if ( ClipMode() && GlobalClipPoints_Find( mousePosition, (VIEWTYPE)m_viewType, m_fScale ) != 0 ) {
974 cursor = gdk_cursor_new( GDK_CROSSHAIR );
975 gdk_window_set_cursor( gtk_widget_get_window(m_gl_widget), cursor );
976 gdk_cursor_unref( cursor );
980 gdk_window_set_cursor( gtk_widget_get_window(m_gl_widget), 0 );
984 unsigned int MoveCamera_buttons(){
985 return RAD_CONTROL | ( g_glwindow_globals.m_nMouseType == ETwoButton ? RAD_RBUTTON : RAD_MBUTTON );
988 void XYWnd_PositionCamera( XYWnd* xywnd, int x, int y, CamWnd& camwnd ){
989 Vector3 origin( Camera_getOrigin( camwnd ) );
990 xywnd->XY_ToPoint( x, y, origin );
991 xywnd->XY_SnapToGrid( origin );
992 Camera_setOrigin( camwnd, origin );
995 unsigned int OrientCamera_buttons(){
996 if ( g_glwindow_globals.m_nMouseType == ETwoButton ) {
997 return RAD_RBUTTON | RAD_SHIFT | RAD_CONTROL;
1002 void XYWnd_OrientCamera( XYWnd* xywnd, int x, int y, CamWnd& camwnd ){
1003 Vector3 point = g_vector3_identity;
1004 xywnd->XY_ToPoint( x, y, point );
1005 xywnd->XY_SnapToGrid( point );
1006 vector3_subtract( point, Camera_getOrigin( camwnd ) );
1008 int n1 = ( xywnd->GetViewType() == XY ) ? 1 : 2;
1009 int n2 = ( xywnd->GetViewType() == YZ ) ? 1 : 0;
1010 int nAngle = ( xywnd->GetViewType() == XY ) ? CAMERA_YAW : CAMERA_PITCH;
1011 if ( point[n1] || point[n2] ) {
1012 Vector3 angles( Camera_getAngles( camwnd ) );
1013 angles[nAngle] = static_cast<float>( radians_to_degrees( atan2( point[n1], point[n2] ) ) );
1014 Camera_setAngles( camwnd, angles );
1023 unsigned int NewBrushDrag_buttons(){
1027 void XYWnd::NewBrushDrag_Begin( int x, int y ){
1029 m_nNewBrushPressx = x;
1030 m_nNewBrushPressy = y;
1032 m_bNewBrushDrag = true;
1033 GlobalUndoSystem().start();
1036 void XYWnd::NewBrushDrag_End( int x, int y ){
1037 if ( m_NewBrushDrag != 0 ) {
1038 GlobalUndoSystem().finish( "brushDragNew" );
1042 void XYWnd::NewBrushDrag( int x, int y ){
1044 XY_ToPoint( m_nNewBrushPressx, m_nNewBrushPressy, mins );
1045 XY_SnapToGrid( mins );
1046 XY_ToPoint( x, y, maxs );
1047 XY_SnapToGrid( maxs );
1049 int nDim = ( m_viewType == XY ) ? 2 : ( m_viewType == YZ ) ? 0 : 1;
1051 mins[nDim] = float_snapped( Select_getWorkZone().d_work_min[nDim], GetSnapGridSize() );
1052 maxs[nDim] = float_snapped( Select_getWorkZone().d_work_max[nDim], GetSnapGridSize() );
1054 if ( maxs[nDim] <= mins[nDim] ) {
1055 maxs[nDim] = mins[nDim] + GetGridSize();
1058 for ( int i = 0 ; i < 3 ; i++ )
1060 if ( mins[i] == maxs[i] ) {
1061 return; // don't create a degenerate brush
1063 if ( mins[i] > maxs[i] ) {
1064 float temp = mins[i];
1070 if ( m_NewBrushDrag == 0 ) {
1071 NodeSmartReference node( GlobalBrushCreator().createBrush() );
1072 Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->insert( node );
1074 scene::Path brushpath( makeReference( GlobalSceneGraph().root() ) );
1075 brushpath.push( makeReference( *Map_GetWorldspawn( g_map ) ) );
1076 brushpath.push( makeReference( node.get() ) );
1077 selectPath( brushpath, true );
1079 m_NewBrushDrag = node.get_pointer();
1083 //Scene_BrushResize_Selected(GlobalSceneGraph(), aabb_for_minmax(mins, maxs), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()));
1084 Scene_BrushResize_Selected( GlobalSceneGraph(), aabb_for_minmax( mins, maxs ),
1085 g_brush_always_caulk ?
1086 "textures/common/caulk" : TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ) );
1089 void entitycreate_activated( ui::Widget item ){
1090 scene::Node* world_node = Map_FindWorldspawn( g_map );
1091 const char* entity_name = gtk_label_get_text( GTK_LABEL( gtk_bin_get_child(GTK_BIN( item )) ) );
1093 if ( !( world_node && string_equal( entity_name, "worldspawn" ) ) ) {
1094 g_pParentWnd->ActiveXY()->OnEntityCreate( entity_name );
1097 GlobalRadiant().m_pfnMessageBox( MainFrame_getWindow(), "There's already a worldspawn in your map!"
1105 void EntityClassMenu_addItem( ui::Menu menu, const char* name ){
1106 auto item = ui::MenuItem( name );
1107 item.connect( "activate", G_CALLBACK( entitycreate_activated ), item );
1109 menu_add_item( menu, item );
1112 class EntityClassMenuInserter : public EntityClassVisitor
1114 typedef std::pair<ui::Menu, CopiedString> MenuPair;
1115 typedef std::vector<MenuPair> MenuStack;
1117 CopiedString m_previous;
1119 EntityClassMenuInserter( ui::Menu menu ){
1120 m_stack.reserve( 2 );
1121 m_stack.push_back( MenuPair( menu, "" ) );
1123 ~EntityClassMenuInserter(){
1124 if ( !string_empty( m_previous.c_str() ) ) {
1125 addItem( m_previous.c_str(), "" );
1128 void visit( EntityClass* e ){
1129 ASSERT_MESSAGE( !string_empty( e->name() ), "entity-class has no name" );
1130 if ( !string_empty( m_previous.c_str() ) ) {
1131 addItem( m_previous.c_str(), e->name() );
1133 m_previous = e->name();
1135 void pushMenu( const CopiedString& name ){
1136 auto item = ui::MenuItem( name.c_str() );
1138 m_stack.back().first.add(item);
1140 auto submenu = ui::Menu(ui::New);
1141 gtk_menu_item_set_submenu( item, submenu );
1143 m_stack.push_back( MenuPair( submenu, name ) );
1148 void addItem( const char* name, const char* next ){
1149 const char* underscore = strchr( name, '_' );
1151 if ( underscore != 0 && underscore != name ) {
1152 bool nextEqual = string_equal_n( name, next, ( underscore + 1 ) - name );
1153 const char* parent = m_stack.back().second.c_str();
1155 if ( !string_empty( parent )
1156 && string_length( parent ) == std::size_t( underscore - name )
1157 && string_equal_n( name, parent, underscore - name ) ) { // this is a child
1159 else if ( nextEqual ) {
1160 if ( m_stack.size() == 2 ) {
1163 pushMenu( CopiedString( StringRange( name, underscore ) ) );
1165 else if ( m_stack.size() == 2 ) {
1169 else if ( m_stack.size() == 2 ) {
1173 EntityClassMenu_addItem( m_stack.back().first, name );
1177 void XYWnd::OnContextMenu(){
1178 if ( g_xywindow_globals.m_bRightClick == false ) {
1182 if ( !m_mnuDrop ) { // first time, load it up
1183 auto menu = m_mnuDrop = ui::Menu(ui::New);
1185 EntityClassMenuInserter inserter( menu );
1186 GlobalEntityClassManager().forEach( inserter );
1189 gtk_menu_popup( m_mnuDrop, 0, 0, 0, 0, 1, GDK_CURRENT_TIME );
1192 FreezePointer g_xywnd_freezePointer;
1194 unsigned int Move_buttons(){
1198 void XYWnd_moveDelta( int x, int y, unsigned int state, void* data ){
1199 reinterpret_cast<XYWnd*>( data )->EntityCreate_MouseMove( x, y );
1200 reinterpret_cast<XYWnd*>( data )->Scroll( -x, y );
1203 gboolean XYWnd_Move_focusOut( ui::Widget widget, GdkEventFocus* event, XYWnd* xywnd ){
1208 void XYWnd::Move_Begin(){
1209 if ( m_move_started ) {
1212 m_move_started = true;
1213 g_xywnd_freezePointer.freeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), XYWnd_moveDelta, this );
1214 m_move_focusOut = m_gl_widget.connect( "focus_out_event", G_CALLBACK( XYWnd_Move_focusOut ), this );
1217 void XYWnd::Move_End(){
1218 m_move_started = false;
1219 g_xywnd_freezePointer.unfreeze_pointer( m_parent ? m_parent : MainFrame_getWindow() );
1220 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_move_focusOut );
1223 unsigned int Zoom_buttons(){
1224 return RAD_RBUTTON | RAD_SHIFT;
1229 void XYWnd_zoomDelta( int x, int y, unsigned int state, void* data ){
1232 while ( abs( g_dragZoom ) > 8 )
1234 if ( g_dragZoom > 0 ) {
1235 reinterpret_cast<XYWnd*>( data )->ZoomOut();
1240 reinterpret_cast<XYWnd*>( data )->ZoomIn();
1247 gboolean XYWnd_Zoom_focusOut( ui::Widget widget, GdkEventFocus* event, XYWnd* xywnd ){
1252 void XYWnd::Zoom_Begin(){
1253 if ( m_zoom_started ) {
1256 m_zoom_started = true;
1258 g_xywnd_freezePointer.freeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), XYWnd_zoomDelta, this );
1259 m_zoom_focusOut = m_gl_widget.connect( "focus_out_event", G_CALLBACK( XYWnd_Zoom_focusOut ), this );
1262 void XYWnd::Zoom_End(){
1263 m_zoom_started = false;
1264 g_xywnd_freezePointer.unfreeze_pointer( m_parent ? m_parent : MainFrame_getWindow() );
1265 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_zoom_focusOut );
1268 // makes sure the selected brush or camera is in view
1269 void XYWnd::PositionView( const Vector3& position ){
1270 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1271 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1273 m_vOrigin[nDim1] = position[nDim1];
1274 m_vOrigin[nDim2] = position[nDim2];
1278 XYWnd_Update( *this );
1281 void XYWnd::SetViewType( VIEWTYPE viewType ){
1282 m_viewType = viewType;
1286 gtk_window_set_title( m_parent, ViewType_getTitle( m_viewType ) );
1291 inline WindowVector WindowVector_forInteger( int x, int y ){
1292 return WindowVector( static_cast<float>( x ), static_cast<float>( y ) );
1295 void XYWnd::mouseDown( const WindowVector& position, ButtonIdentifier button, ModifierFlags modifiers ){
1296 XY_MouseDown( static_cast<int>( position.x() ), static_cast<int>( position.y() ), buttons_for_button_and_modifiers( button, modifiers ) );
1298 void XYWnd::XY_MouseDown( int x, int y, unsigned int buttons ){
1299 if ( buttons == Move_buttons() ) {
1301 EntityCreate_MouseDown( x, y );
1303 else if ( buttons == Zoom_buttons() ) {
1306 else if ( ClipMode() && buttons == Clipper_buttons() ) {
1307 Clipper_OnLButtonDown( x, y );
1309 else if ( buttons == NewBrushDrag_buttons() && GlobalSelectionSystem().countSelected() == 0 ) {
1310 NewBrushDrag_Begin( x, y );
1312 // control mbutton = move camera
1313 else if ( buttons == MoveCamera_buttons() ) {
1314 XYWnd_PositionCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1316 // mbutton = angle camera
1317 else if ( buttons == OrientCamera_buttons() ) {
1318 XYWnd_OrientCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1322 m_window_observer->onMouseDown( WindowVector_forInteger( x, y ), button_for_flags( buttons ), modifiers_for_flags( buttons ) );
1326 void XYWnd::XY_MouseUp( int x, int y, unsigned int buttons ){
1327 if ( m_move_started ) {
1329 EntityCreate_MouseUp( x, y );
1331 else if ( m_zoom_started ) {
1334 else if ( ClipMode() && buttons == Clipper_buttons() ) {
1335 Clipper_OnLButtonUp( x, y );
1337 else if ( m_bNewBrushDrag ) {
1338 m_bNewBrushDrag = false;
1339 NewBrushDrag_End( x, y );
1343 m_window_observer->onMouseUp( WindowVector_forInteger( x, y ), button_for_flags( buttons ), modifiers_for_flags( buttons ) );
1347 void XYWnd::XY_MouseMoved( int x, int y, unsigned int buttons ){
1348 // rbutton = drag xy origin
1349 if ( m_move_started ) {
1352 else if ( m_zoom_started ) {
1355 else if ( ClipMode() && g_pMovingClip != 0 ) {
1356 Clipper_OnMouseMoved( x, y );
1358 // lbutton without selection = drag new brush
1359 else if ( m_bNewBrushDrag ) {
1360 NewBrushDrag( x, y );
1363 // control mbutton = move camera
1364 else if ( getButtonState() == MoveCamera_buttons() ) {
1365 XYWnd_PositionCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1368 // mbutton = angle camera
1369 else if ( getButtonState() == OrientCamera_buttons() ) {
1370 XYWnd_OrientCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1375 m_window_observer->onMouseMotion( WindowVector_forInteger( x, y ), modifiers_for_flags( buttons ) );
1377 m_mousePosition[0] = m_mousePosition[1] = m_mousePosition[2] = 0.0;
1378 XY_ToPoint( x, y, m_mousePosition );
1379 XY_SnapToGrid( m_mousePosition );
1381 StringOutputStream status( 64 );
1382 status << "x:: " << FloatFormat( m_mousePosition[0], 6, 1 )
1383 << " y:: " << FloatFormat( m_mousePosition[1], 6, 1 )
1384 << " z:: " << FloatFormat( m_mousePosition[2], 6, 1 );
1385 g_pParentWnd->SetStatusText( g_pParentWnd->m_position_status, status.c_str() );
1387 if ( g_xywindow_globals_private.g_bCrossHairs ) {
1388 XYWnd_Update( *this );
1391 Clipper_Crosshair_OnMouseMoved( x, y );
1395 void XYWnd::EntityCreate_MouseDown( int x, int y ){
1396 m_entityCreate = true;
1397 m_entityCreate_x = x;
1398 m_entityCreate_y = y;
1401 void XYWnd::EntityCreate_MouseMove( int x, int y ){
1402 if ( m_entityCreate && ( m_entityCreate_x != x || m_entityCreate_y != y ) ) {
1403 m_entityCreate = false;
1407 void XYWnd::EntityCreate_MouseUp( int x, int y ){
1408 if ( m_entityCreate ) {
1409 m_entityCreate = false;
1414 inline float screen_normalised( int pos, unsigned int size ){
1415 return ( ( 2.0f * pos ) / size ) - 1.0f;
1418 inline float normalised_to_world( float normalised, float world_origin, float normalised2world_scale ){
1419 return world_origin + normalised * normalised2world_scale;
1423 // TTimo: watch it, this doesn't init one of the 3 coords
1424 void XYWnd::XY_ToPoint( int x, int y, Vector3& point ){
1425 float normalised2world_scale_x = m_nWidth / 2 / m_fScale;
1426 float normalised2world_scale_y = m_nHeight / 2 / m_fScale;
1427 if ( m_viewType == XY ) {
1428 point[0] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[0], normalised2world_scale_x );
1429 point[1] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[1], normalised2world_scale_y );
1431 else if ( m_viewType == YZ ) {
1432 point[1] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[1], normalised2world_scale_x );
1433 point[2] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[2], normalised2world_scale_y );
1437 point[0] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[0], normalised2world_scale_x );
1438 point[2] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[2], normalised2world_scale_y );
1442 void XYWnd::XY_SnapToGrid( Vector3& point ){
1443 if ( m_viewType == XY ) {
1444 point[0] = float_snapped( point[0], GetSnapGridSize() );
1445 point[1] = float_snapped( point[1], GetSnapGridSize() );
1447 else if ( m_viewType == YZ ) {
1448 point[1] = float_snapped( point[1], GetSnapGridSize() );
1449 point[2] = float_snapped( point[2], GetSnapGridSize() );
1453 point[0] = float_snapped( point[0], GetSnapGridSize() );
1454 point[2] = float_snapped( point[2], GetSnapGridSize() );
1458 void XYWnd::XY_LoadBackgroundImage( const char *name ){
1459 const char* relative = path_make_relative( name, GlobalFileSystem().findRoot( name ) );
1460 if ( relative == name ) {
1461 globalOutputStream() << "WARNING: could not extract the relative path, using full path instead\n";
1464 char fileNameWithoutExt[512];
1465 strncpy( fileNameWithoutExt, relative, sizeof( fileNameWithoutExt ) - 1 );
1466 fileNameWithoutExt[512 - 1] = '\0';
1467 fileNameWithoutExt[strlen( fileNameWithoutExt ) - 4] = '\0';
1469 Image *image = QERApp_LoadImage( 0, fileNameWithoutExt );
1471 globalOutputStream() << "Could not load texture " << fileNameWithoutExt << "\n";
1474 g_pParentWnd->ActiveXY()->m_tex = (qtexture_t*)malloc( sizeof( qtexture_t ) );
1475 LoadTextureRGBA( g_pParentWnd->ActiveXY()->XYWnd::m_tex, image->getRGBAPixels(), image->getWidth(), image->getHeight() );
1476 globalOutputStream() << "Loaded background texture " << relative << "\n";
1477 g_pParentWnd->ActiveXY()->m_backgroundActivated = true;
1480 switch ( g_pParentWnd->ActiveXY()->m_viewType )
1497 Select_GetBounds( min, max );
1498 g_pParentWnd->ActiveXY()->m_xmin = min[m_ix];
1499 g_pParentWnd->ActiveXY()->m_ymin = min[m_iy];
1500 g_pParentWnd->ActiveXY()->m_xmax = max[m_ix];
1501 g_pParentWnd->ActiveXY()->m_ymax = max[m_iy];
1504 void XYWnd::XY_DisableBackground( void ){
1505 g_pParentWnd->ActiveXY()->m_backgroundActivated = false;
1506 if ( g_pParentWnd->ActiveXY()->m_tex ) {
1507 free( g_pParentWnd->ActiveXY()->m_tex );
1509 g_pParentWnd->ActiveXY()->m_tex = NULL;
1512 void WXY_BackgroundSelect( void ){
1513 bool brushesSelected = Scene_countSelectedBrushes( GlobalSceneGraph() ) != 0;
1514 if ( !brushesSelected ) {
1515 ui::alert( ui::root, "You have to select some brushes to get the bounding box for.\n",
1516 "No selection", ui::alert_type::OK, ui::alert_icon::Error );
1520 const char *filename = MainFrame_getWindow().file_dialog( TRUE, "Background Image", NULL, NULL );
1521 g_pParentWnd->ActiveXY()->XY_DisableBackground();
1523 g_pParentWnd->ActiveXY()->XY_LoadBackgroundImage( filename );
1528 ============================================================================
1532 ============================================================================
1541 double two_to_the_power( int power ){
1542 return pow( 2.0f, power );
1545 void XYWnd::XY_DrawAxis( void ){
1546 if ( g_xywindow_globals_private.show_axis ) {
1547 const char g_AxisName[3] = { 'X', 'Y', 'Z' };
1548 const int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1549 const int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1550 const int w = ( m_nWidth / 2 / m_fScale );
1551 const int h = ( m_nHeight / 2 / m_fScale );
1553 const Vector3& colourX = ( m_viewType == YZ ) ? g_xywindow_globals.AxisColorY : g_xywindow_globals.AxisColorX;
1554 const Vector3& colourY = ( m_viewType == XY ) ? g_xywindow_globals.AxisColorY : g_xywindow_globals.AxisColorZ;
1556 // draw two lines with corresponding axis colors to highlight current view
1557 // horizontal line: nDim1 color
1559 glBegin( GL_LINES );
1560 glColor3fv( vector3_to_array( colourX ) );
1561 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1562 glVertex2f( m_vOrigin[nDim1] - w + 65 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1564 glVertex2f( 32 / m_fScale, 0 );
1565 glColor3fv( vector3_to_array( colourY ) );
1566 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1567 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 20 / m_fScale );
1569 glVertex2f( 0, 32 / m_fScale );
1572 // now print axis symbols
1573 glColor3fv( vector3_to_array( colourX ) );
1574 glRasterPos2f( m_vOrigin[nDim1] - w + 55 / m_fScale, m_vOrigin[nDim2] + h - 55 / m_fScale );
1575 GlobalOpenGL().drawChar( g_AxisName[nDim1] );
1576 glRasterPos2f( 28 / m_fScale, -10 / m_fScale );
1577 GlobalOpenGL().drawChar( g_AxisName[nDim1] );
1578 glColor3fv( vector3_to_array( colourY ) );
1579 glRasterPos2f( m_vOrigin[nDim1] - w + 25 / m_fScale, m_vOrigin[nDim2] + h - 30 / m_fScale );
1580 GlobalOpenGL().drawChar( g_AxisName[nDim2] );
1581 glRasterPos2f( -10 / m_fScale, 28 / m_fScale );
1582 GlobalOpenGL().drawChar( g_AxisName[nDim2] );
1586 void XYWnd::XY_DrawBackground( void ){
1587 glPushAttrib( GL_ALL_ATTRIB_BITS );
1589 glEnable( GL_TEXTURE_2D );
1590 glEnable( GL_BLEND );
1591 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
1592 glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1593 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
1594 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
1596 glPolygonMode( GL_FRONT, GL_FILL );
1598 glBindTexture( GL_TEXTURE_2D, m_tex->texture_number );
1599 glBegin( GL_QUADS );
1601 glColor4f( 1.0, 1.0, 1.0, m_alpha );
1602 glTexCoord2f( 0.0, 1.0 );
1603 glVertex2f( m_xmin, m_ymin );
1605 glTexCoord2f( 1.0, 1.0 );
1606 glVertex2f( m_xmax, m_ymin );
1608 glTexCoord2f( 1.0, 0.0 );
1609 glVertex2f( m_xmax, m_ymax );
1611 glTexCoord2f( 0.0, 0.0 );
1612 glVertex2f( m_xmin, m_ymax );
1615 glBindTexture( GL_TEXTURE_2D, 0 );
1620 void XYWnd::XY_DrawGrid( void ) {
1621 float x, y, xb, xe, yb, ye;
1624 float step, minor_step, stepx, stepy;
1625 step = minor_step = stepx = stepy = GetGridSize();
1627 int minor_power = Grid_getPower();
1630 while ( ( minor_step * m_fScale ) <= 4.0f ) { // make sure minor grid spacing is at least 4 pixels on the screen
1634 int power = minor_power;
1635 while ( ( power % 3 ) != 0 || ( step * m_fScale ) <= 32.0f ) { // make sure major grid spacing is at least 32 pixels on the screen
1637 step = float(two_to_the_power( power ) );
1639 mask = ( 1 << ( power - minor_power ) ) - 1;
1640 while ( ( stepx * m_fScale ) <= 32.0f ) // text step x must be at least 32
1642 while ( ( stepy * m_fScale ) <= 32.0f ) // text step y must be at least 32
1645 a = ( ( GetSnapGridSize() > 0.0f ) ? 1.0f : 0.3f );
1647 glDisable( GL_TEXTURE_2D );
1648 glDisable( GL_TEXTURE_1D );
1649 glDisable( GL_DEPTH_TEST );
1650 glDisable( GL_BLEND );
1653 w = ( m_nWidth / 2 / m_fScale );
1654 h = ( m_nHeight / 2 / m_fScale );
1656 const int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1657 const int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1659 xb = m_vOrigin[nDim1] - w;
1660 if ( xb < region_mins[nDim1] ) {
1661 xb = region_mins[nDim1];
1663 xb = step * floor( xb / step );
1665 xe = m_vOrigin[nDim1] + w;
1666 if ( xe > region_maxs[nDim1] ) {
1667 xe = region_maxs[nDim1];
1669 xe = step * ceil( xe / step );
1671 yb = m_vOrigin[nDim2] - h;
1672 if ( yb < region_mins[nDim2] ) {
1673 yb = region_mins[nDim2];
1675 yb = step * floor( yb / step );
1677 ye = m_vOrigin[nDim2] + h;
1678 if ( ye > region_maxs[nDim2] ) {
1679 ye = region_maxs[nDim2];
1681 ye = step * ceil( ye / step );
1683 #define COLORS_DIFFER( a,b ) \
1684 ( ( a )[0] != ( b )[0] || \
1685 ( a )[1] != ( b )[1] || \
1686 ( a )[2] != ( b )[2] )
1689 // draw minor blocks
1690 if ( g_xywindow_globals_private.d_showgrid || a < 1.0f ) {
1692 glEnable( GL_BLEND );
1695 if ( COLORS_DIFFER( g_xywindow_globals.color_gridminor, g_xywindow_globals.color_gridback ) ) {
1696 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridminor, a ) ) );
1698 glBegin( GL_LINES );
1700 for ( x = xb ; x < xe ; x += minor_step, ++i ) {
1701 if ( ( i & mask ) != 0 ) {
1702 glVertex2f( x, yb );
1703 glVertex2f( x, ye );
1707 for ( y = yb ; y < ye ; y += minor_step, ++i ) {
1708 if ( ( i & mask ) != 0 ) {
1709 glVertex2f( xb, y );
1710 glVertex2f( xe, y );
1716 // draw major blocks
1717 if ( COLORS_DIFFER( g_xywindow_globals.color_gridmajor, g_xywindow_globals.color_gridminor ) ) {
1718 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridmajor, a ) ) );
1720 glBegin( GL_LINES );
1721 for ( x = xb ; x <= xe ; x += step ) {
1722 glVertex2f( x, yb );
1723 glVertex2f( x, ye );
1725 for ( y = yb ; y <= ye ; y += step ) {
1726 glVertex2f( xb, y );
1727 glVertex2f( xe, y );
1733 glDisable( GL_BLEND );
1737 // draw coordinate text if needed
1738 if ( g_xywindow_globals_private.show_coordinates ) {
1739 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridtext, 1.0f ) ) );
1740 float offx = m_vOrigin[nDim2] + h - ( 4 + GlobalOpenGL().m_font->getPixelAscent() ) / m_fScale;
1741 float offy = m_vOrigin[nDim1] - w + 4 / m_fScale;
1742 for ( x = xb - fmod( xb, stepx ); x <= xe ; x += stepx ) {
1743 glRasterPos2f( x, offx );
1744 sprintf( text, "%g", x );
1745 GlobalOpenGL().drawString( text );
1747 for ( y = yb - fmod( yb, stepy ); y <= ye ; y += stepy ) {
1748 glRasterPos2f( offy, y );
1749 sprintf( text, "%g", y );
1750 GlobalOpenGL().drawString( text );
1754 glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) );
1757 // we do this part (the old way) only if show_axis is disabled
1758 if ( !g_xywindow_globals_private.show_axis ) {
1759 glRasterPos2f( m_vOrigin[nDim1] - w + 35 / m_fScale, m_vOrigin[nDim2] + h - 20 / m_fScale );
1761 GlobalOpenGL().drawString( ViewType_getTitle( m_viewType ) );
1765 XYWnd::XY_DrawAxis();
1767 // show current work zone?
1768 // the work zone is used to place dropped points and brushes
1769 if ( g_xywindow_globals_private.d_show_work ) {
1770 glColor4f( 1.0f, 0.0f, 0.0f, 1.0f );
1771 glBegin( GL_LINES );
1772 glVertex2f( xb, Select_getWorkZone().d_work_min[nDim2] );
1773 glVertex2f( xe, Select_getWorkZone().d_work_min[nDim2] );
1774 glVertex2f( xb, Select_getWorkZone().d_work_max[nDim2] );
1775 glVertex2f( xe, Select_getWorkZone().d_work_max[nDim2] );
1776 glVertex2f( Select_getWorkZone().d_work_min[nDim1], yb );
1777 glVertex2f( Select_getWorkZone().d_work_min[nDim1], ye );
1778 glVertex2f( Select_getWorkZone().d_work_max[nDim1], yb );
1779 glVertex2f( Select_getWorkZone().d_work_max[nDim1], ye );
1789 void XYWnd::XY_DrawBlockGrid(){
1790 if ( Map_FindWorldspawn( g_map ) == 0 ) {
1793 const char *value = Node_getEntity( *Map_GetWorldspawn( g_map ) )->getKeyValue( "_blocksize" );
1794 if ( strlen( value ) ) {
1795 sscanf( value, "%i", &g_xywindow_globals_private.blockSize );
1798 if ( !g_xywindow_globals_private.blockSize || g_xywindow_globals_private.blockSize > 65536 || g_xywindow_globals_private.blockSize < 1024 ) {
1799 // don't use custom blocksize if it is less than the default, or greater than the maximum world coordinate
1800 g_xywindow_globals_private.blockSize = 1024;
1803 float x, y, xb, xe, yb, ye;
1807 glDisable( GL_TEXTURE_2D );
1808 glDisable( GL_TEXTURE_1D );
1809 glDisable( GL_DEPTH_TEST );
1810 glDisable( GL_BLEND );
1812 w = ( m_nWidth / 2 / m_fScale );
1813 h = ( m_nHeight / 2 / m_fScale );
1815 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1816 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1818 xb = m_vOrigin[nDim1] - w;
1819 if ( xb < region_mins[nDim1] ) {
1820 xb = region_mins[nDim1];
1822 xb = static_cast<float>( g_xywindow_globals_private.blockSize * floor( xb / g_xywindow_globals_private.blockSize ) );
1824 xe = m_vOrigin[nDim1] + w;
1825 if ( xe > region_maxs[nDim1] ) {
1826 xe = region_maxs[nDim1];
1828 xe = static_cast<float>( g_xywindow_globals_private.blockSize * ceil( xe / g_xywindow_globals_private.blockSize ) );
1830 yb = m_vOrigin[nDim2] - h;
1831 if ( yb < region_mins[nDim2] ) {
1832 yb = region_mins[nDim2];
1834 yb = static_cast<float>( g_xywindow_globals_private.blockSize * floor( yb / g_xywindow_globals_private.blockSize ) );
1836 ye = m_vOrigin[nDim2] + h;
1837 if ( ye > region_maxs[nDim2] ) {
1838 ye = region_maxs[nDim2];
1840 ye = static_cast<float>( g_xywindow_globals_private.blockSize * ceil( ye / g_xywindow_globals_private.blockSize ) );
1842 // draw major blocks
1844 glColor3fv( vector3_to_array( g_xywindow_globals.color_gridblock ) );
1847 glBegin( GL_LINES );
1849 for ( x = xb ; x <= xe ; x += g_xywindow_globals_private.blockSize )
1851 glVertex2f( x, yb );
1852 glVertex2f( x, ye );
1855 if ( m_viewType == XY ) {
1856 for ( y = yb ; y <= ye ; y += g_xywindow_globals_private.blockSize )
1858 glVertex2f( xb, y );
1859 glVertex2f( xe, y );
1866 // draw coordinate text if needed
1868 if ( m_viewType == XY && m_fScale > .1 ) {
1869 for ( x = xb ; x < xe ; x += g_xywindow_globals_private.blockSize )
1870 for ( y = yb ; y < ye ; y += g_xywindow_globals_private.blockSize )
1872 glRasterPos2f( x + ( g_xywindow_globals_private.blockSize / 2 ), y + ( g_xywindow_globals_private.blockSize / 2 ) );
1873 sprintf( text, "%i,%i",(int)floor( x / g_xywindow_globals_private.blockSize ), (int)floor( y / g_xywindow_globals_private.blockSize ) );
1874 GlobalOpenGL().drawString( text );
1878 glColor4f( 0, 0, 0, 0 );
1881 void XYWnd::DrawCameraIcon( const Vector3& origin, const Vector3& angles ){
1882 float x, y, fov, box;
1885 fov = 48 / m_fScale;
1886 box = 16 / m_fScale;
1888 if ( m_viewType == XY ) {
1891 a = degrees_to_radians( angles[CAMERA_YAW] );
1893 else if ( m_viewType == YZ ) {
1896 a = degrees_to_radians( angles[CAMERA_PITCH] );
1902 a = degrees_to_radians( angles[CAMERA_PITCH] );
1905 glColor3f( 0.0, 0.0, 1.0 );
1906 glBegin( GL_LINE_STRIP );
1907 glVertex3f( x - box,y,0 );
1908 glVertex3f( x,y + ( box / 2 ),0 );
1909 glVertex3f( x + box,y,0 );
1910 glVertex3f( x,y - ( box / 2 ),0 );
1911 glVertex3f( x - box,y,0 );
1912 glVertex3f( x + box,y,0 );
1915 glBegin( GL_LINE_STRIP );
1916 glVertex3f( x + static_cast<float>( fov * cos( a + c_pi / 4 ) ), y + static_cast<float>( fov * sin( a + c_pi / 4 ) ), 0 );
1917 glVertex3f( x, y, 0 );
1918 glVertex3f( x + static_cast<float>( fov * cos( a - c_pi / 4 ) ), y + static_cast<float>( fov * sin( a - c_pi / 4 ) ), 0 );
1924 float Betwixt( float f1, float f2 ){
1926 return f2 + ( ( f1 - f2 ) / 2 );
1929 return f1 + ( ( f2 - f1 ) / 2 );
1934 // can be greatly simplified but per usual i am in a hurry
1935 // which is not an excuse, just a fact
1936 void XYWnd::PaintSizeInfo( int nDim1, int nDim2, Vector3& vMinBounds, Vector3& vMaxBounds ){
1937 if ( vector3_equal( vMinBounds, vMaxBounds ) ) {
1940 const char* g_pDimStrings[] = {"x:", "y:", "z:"};
1941 typedef const char* OrgStrings[2];
1942 const OrgStrings g_pOrgStrings[] = { { "x:", "y:", }, { "x:", "z:", }, { "y:", "z:", } };
1944 Vector3 vSize( vector3_subtracted( vMaxBounds, vMinBounds ) );
1946 glColor3f( g_xywindow_globals.color_selbrushes[0] * .65f,
1947 g_xywindow_globals.color_selbrushes[1] * .65f,
1948 g_xywindow_globals.color_selbrushes[2] * .65f );
1950 StringOutputStream dimensions( 16 );
1952 if ( m_viewType == XY ) {
1953 glBegin( GL_LINES );
1955 glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f );
1956 glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
1958 glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
1959 glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
1961 glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f );
1962 glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
1965 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2], 0.0f );
1966 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f );
1968 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f );
1969 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f );
1971 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2], 0.0f );
1972 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f );
1976 glRasterPos3f( Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), vMinBounds[nDim2] - 20.0f / m_fScale, 0.0f );
1977 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
1978 GlobalOpenGL().drawString( dimensions.c_str() );
1981 glRasterPos3f( vMaxBounds[nDim1] + 16.0f / m_fScale, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ), 0.0f );
1982 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
1983 GlobalOpenGL().drawString( dimensions.c_str() );
1986 glRasterPos3f( vMinBounds[nDim1] + 4, vMaxBounds[nDim2] + 8 / m_fScale, 0.0f );
1987 dimensions << "(" << g_pOrgStrings[0][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[0][1] << vMaxBounds[nDim2] << ")";
1988 GlobalOpenGL().drawString( dimensions.c_str() );
1990 else if ( m_viewType == XZ ) {
1991 glBegin( GL_LINES );
1993 glVertex3f( vMinBounds[nDim1], 0, vMinBounds[nDim2] - 6.0f / m_fScale );
1994 glVertex3f( vMinBounds[nDim1], 0, vMinBounds[nDim2] - 10.0f / m_fScale );
1996 glVertex3f( vMinBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale );
1997 glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale );
1999 glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 6.0f / m_fScale );
2000 glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale );
2003 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, 0,vMinBounds[nDim2] );
2004 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMinBounds[nDim2] );
2006 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMinBounds[nDim2] );
2007 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMaxBounds[nDim2] );
2009 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, 0,vMaxBounds[nDim2] );
2010 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMaxBounds[nDim2] );
2014 glRasterPos3f( Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), 0, vMinBounds[nDim2] - 20.0f / m_fScale );
2015 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
2016 GlobalOpenGL().drawString( dimensions.c_str() );
2019 glRasterPos3f( vMaxBounds[nDim1] + 16.0f / m_fScale, 0, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ) );
2020 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
2021 GlobalOpenGL().drawString( dimensions.c_str() );
2024 glRasterPos3f( vMinBounds[nDim1] + 4, 0, vMaxBounds[nDim2] + 8 / m_fScale );
2025 dimensions << "(" << g_pOrgStrings[1][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[1][1] << vMaxBounds[nDim2] << ")";
2026 GlobalOpenGL().drawString( dimensions.c_str() );
2030 glBegin( GL_LINES );
2032 glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale );
2033 glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2035 glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2036 glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2038 glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale );
2039 glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2042 glVertex3f( 0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2] );
2043 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2] );
2045 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2] );
2046 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2] );
2048 glVertex3f( 0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2] );
2049 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2] );
2053 glRasterPos3f( 0, Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), vMinBounds[nDim2] - 20.0f / m_fScale );
2054 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
2055 GlobalOpenGL().drawString( dimensions.c_str() );
2058 glRasterPos3f( 0, vMaxBounds[nDim1] + 16.0f / m_fScale, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ) );
2059 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
2060 GlobalOpenGL().drawString( dimensions.c_str() );
2063 glRasterPos3f( 0, vMinBounds[nDim1] + 4.0f, vMaxBounds[nDim2] + 8 / m_fScale );
2064 dimensions << "(" << g_pOrgStrings[2][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[2][1] << vMaxBounds[nDim2] << ")";
2065 GlobalOpenGL().drawString( dimensions.c_str() );
2069 class XYRenderer : public Renderer
2077 unsigned int m_highlight;
2081 XYRenderer( RenderStateFlags globalstate, Shader* selected ) :
2082 m_globalstate( globalstate ),
2083 m_state_selected( selected ){
2084 ASSERT_NOTNULL( selected );
2085 m_state_stack.push_back( state_type() );
2088 void SetState( Shader* state, EStyle style ){
2089 ASSERT_NOTNULL( state );
2090 if ( style == eWireframeOnly ) {
2091 m_state_stack.back().m_state = state;
2094 EStyle getStyle() const {
2095 return eWireframeOnly;
2098 m_state_stack.push_back( m_state_stack.back() );
2101 ASSERT_MESSAGE( !m_state_stack.empty(), "popping empty stack" );
2102 m_state_stack.pop_back();
2104 void Highlight( EHighlightMode mode, bool bEnable = true ){
2106 ? m_state_stack.back().m_highlight |= mode
2107 : m_state_stack.back().m_highlight &= ~mode;
2109 void addRenderable( const OpenGLRenderable& renderable, const Matrix4& localToWorld ){
2110 if ( m_state_stack.back().m_highlight & ePrimitive ) {
2111 m_state_selected->addRenderable( renderable, localToWorld );
2115 m_state_stack.back().m_state->addRenderable( renderable, localToWorld );
2119 void render( const Matrix4& modelview, const Matrix4& projection ){
2120 GlobalShaderCache().render( m_globalstate, modelview, projection );
2123 std::vector<state_type> m_state_stack;
2124 RenderStateFlags m_globalstate;
2125 Shader* m_state_selected;
2128 void XYWnd::updateProjection(){
2129 m_projection[0] = 1.0f / static_cast<float>( m_nWidth / 2 );
2130 m_projection[5] = 1.0f / static_cast<float>( m_nHeight / 2 );
2131 m_projection[10] = 1.0f / ( g_MaxWorldCoord * m_fScale );
2133 m_projection[12] = 0.0f;
2134 m_projection[13] = 0.0f;
2135 m_projection[14] = -1.0f;
2147 m_projection[11] = 0.0f;
2149 m_projection[15] = 1.0f;
2151 m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight );
2154 // note: modelview matrix must have a uniform scale, otherwise strange things happen when rendering the rotation manipulator.
2155 void XYWnd::updateModelview(){
2156 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
2157 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
2160 m_modelview[12] = -m_vOrigin[nDim1] * m_fScale;
2161 m_modelview[13] = -m_vOrigin[nDim2] * m_fScale;
2162 m_modelview[14] = g_MaxWorldCoord * m_fScale;
2165 switch ( m_viewType )
2168 m_modelview[0] = m_fScale;
2173 m_modelview[5] = m_fScale;
2178 m_modelview[10] = -m_fScale;
2181 m_modelview[0] = m_fScale;
2187 m_modelview[6] = m_fScale;
2190 m_modelview[9] = m_fScale;
2191 m_modelview[10] = 0;
2196 m_modelview[2] = -m_fScale;
2198 m_modelview[4] = m_fScale;
2203 m_modelview[9] = m_fScale;
2204 m_modelview[10] = 0;
2208 m_modelview[3] = m_modelview[7] = m_modelview[11] = 0;
2209 m_modelview[15] = 1;
2211 m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight );
2220 //#define DBG_SCENEDUMP
2222 void XYWnd::XY_Draw(){
2226 glViewport( 0, 0, m_nWidth, m_nHeight );
2227 glClearColor( g_xywindow_globals.color_gridback[0],
2228 g_xywindow_globals.color_gridback[1],
2229 g_xywindow_globals.color_gridback[2],0 );
2231 glClear( GL_COLOR_BUFFER_BIT );
2237 glMatrixMode( GL_PROJECTION );
2238 glLoadMatrixf( reinterpret_cast<const float*>( &m_projection ) );
2240 glMatrixMode( GL_MODELVIEW );
2242 glScalef( m_fScale, m_fScale, 1 );
2243 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
2244 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
2245 glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 );
2247 glDisable( GL_LINE_STIPPLE );
2249 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2250 glDisableClientState( GL_NORMAL_ARRAY );
2251 glDisableClientState( GL_COLOR_ARRAY );
2252 glDisable( GL_TEXTURE_2D );
2253 glDisable( GL_LIGHTING );
2254 glDisable( GL_COLOR_MATERIAL );
2255 glDisable( GL_DEPTH_TEST );
2257 if ( m_backgroundActivated ) {
2258 XY_DrawBackground();
2262 if ( g_xywindow_globals_private.show_blocks ) {
2266 glLoadMatrixf( reinterpret_cast<const float*>( &m_modelview ) );
2268 unsigned int globalstate = RENDER_COLOURARRAY | RENDER_COLOURWRITE | RENDER_POLYGONSMOOTH | RENDER_LINESMOOTH;
2269 if ( !g_xywindow_globals.m_bNoStipple ) {
2270 globalstate |= RENDER_LINESTIPPLE;
2274 XYRenderer renderer( globalstate, m_state_selected );
2276 Scene_Render( renderer, m_view );
2278 GlobalOpenGL_debugAssertNoErrors();
2279 renderer.render( m_modelview, m_projection );
2280 GlobalOpenGL_debugAssertNoErrors();
2283 glDepthMask( GL_FALSE );
2285 GlobalOpenGL_debugAssertNoErrors();
2287 glLoadMatrixf( reinterpret_cast<const float*>( &m_modelview ) );
2289 GlobalOpenGL_debugAssertNoErrors();
2290 glDisable( GL_LINE_STIPPLE );
2291 GlobalOpenGL_debugAssertNoErrors();
2293 GlobalOpenGL_debugAssertNoErrors();
2294 if ( GlobalOpenGL().GL_1_3() ) {
2295 glActiveTexture( GL_TEXTURE0 );
2296 glClientActiveTexture( GL_TEXTURE0 );
2298 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2299 GlobalOpenGL_debugAssertNoErrors();
2300 glDisableClientState( GL_NORMAL_ARRAY );
2301 GlobalOpenGL_debugAssertNoErrors();
2302 glDisableClientState( GL_COLOR_ARRAY );
2303 GlobalOpenGL_debugAssertNoErrors();
2304 glDisable( GL_TEXTURE_2D );
2305 GlobalOpenGL_debugAssertNoErrors();
2306 glDisable( GL_LIGHTING );
2307 GlobalOpenGL_debugAssertNoErrors();
2308 glDisable( GL_COLOR_MATERIAL );
2309 GlobalOpenGL_debugAssertNoErrors();
2311 GlobalOpenGL_debugAssertNoErrors();
2315 if ( g_xywindow_globals_private.m_bSizePaint && GlobalSelectionSystem().countSelected() != 0 ) {
2317 Select_GetBounds( min, max );
2318 PaintSizeInfo( nDim1, nDim2, min, max );
2321 if ( g_xywindow_globals_private.g_bCrossHairs ) {
2322 glColor4f( 0.2f, 0.9f, 0.2f, 0.8f );
2323 glBegin( GL_LINES );
2324 if ( m_viewType == XY ) {
2325 glVertex2f( 2.0f * g_MinWorldCoord, m_mousePosition[1] );
2326 glVertex2f( 2.0f * g_MaxWorldCoord, m_mousePosition[1] );
2327 glVertex2f( m_mousePosition[0], 2.0f * g_MinWorldCoord );
2328 glVertex2f( m_mousePosition[0], 2.0f * g_MaxWorldCoord );
2330 else if ( m_viewType == YZ ) {
2331 glVertex3f( m_mousePosition[0], 2.0f * g_MinWorldCoord, m_mousePosition[2] );
2332 glVertex3f( m_mousePosition[0], 2.0f * g_MaxWorldCoord, m_mousePosition[2] );
2333 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MinWorldCoord );
2334 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MaxWorldCoord );
2338 glVertex3f( 2.0f * g_MinWorldCoord, m_mousePosition[1], m_mousePosition[2] );
2339 glVertex3f( 2.0f * g_MaxWorldCoord, m_mousePosition[1], m_mousePosition[2] );
2340 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MinWorldCoord );
2341 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MaxWorldCoord );
2347 GlobalClipPoints_Draw( m_fScale );
2350 GlobalOpenGL_debugAssertNoErrors();
2354 glScalef( m_fScale, m_fScale, 1 );
2355 glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 );
2357 DrawCameraIcon( Camera_getOrigin( *g_pParentWnd->GetCamWnd() ), Camera_getAngles( *g_pParentWnd->GetCamWnd() ) );
2359 Feedback_draw2D( m_viewType );
2361 if ( g_xywindow_globals_private.show_outline ) {
2363 glMatrixMode( GL_PROJECTION );
2365 glOrtho( 0, m_nWidth, 0, m_nHeight, 0, 1 );
2367 glMatrixMode( GL_MODELVIEW );
2370 // four view mode doesn't colorize
2371 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) {
2372 glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) );
2376 switch ( m_viewType )
2379 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorX ) );
2382 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorY ) );
2385 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorZ ) );
2389 glBegin( GL_LINE_LOOP );
2390 glVertex2f( 0.5, 0.5 );
2391 glVertex2f( m_nWidth - 0.5, 1 );
2392 glVertex2f( m_nWidth - 0.5, m_nHeight - 0.5 );
2393 glVertex2f( 0.5, m_nHeight - 0.5 );
2398 GlobalOpenGL_debugAssertNoErrors();
2403 void XYWnd_MouseToPoint( XYWnd* xywnd, int x, int y, Vector3& point ){
2404 xywnd->XY_ToPoint( x, y, point );
2405 xywnd->XY_SnapToGrid( point );
2407 int nDim = ( xywnd->GetViewType() == XY ) ? 2 : ( xywnd->GetViewType() == YZ ) ? 0 : 1;
2408 float fWorkMid = float_mid( Select_getWorkZone().d_work_min[nDim], Select_getWorkZone().d_work_max[nDim] );
2409 point[nDim] = float_snapped( fWorkMid, GetGridSize() );
2412 void XYWnd::OnEntityCreate( const char* item ){
2413 StringOutputStream command;
2414 command << "entityCreate -class " << item;
2415 UndoableCommand undo( command.c_str() );
2417 XYWnd_MouseToPoint( this, m_entityCreate_x, m_entityCreate_y, point );
2418 Entity_createFromSelection( item, point );
2423 void GetFocusPosition( Vector3& position ){
2424 if ( GlobalSelectionSystem().countSelected() != 0 ) {
2425 Select_GetMid( position );
2429 position = Camera_getOrigin( *g_pParentWnd->GetCamWnd() );
2433 void XYWnd_Focus( XYWnd* xywnd ){
2435 GetFocusPosition( position );
2436 xywnd->PositionView( position );
2439 void XY_Split_Focus(){
2441 GetFocusPosition( position );
2442 if ( g_pParentWnd->GetXYWnd() ) {
2443 g_pParentWnd->GetXYWnd()->PositionView( position );
2445 if ( g_pParentWnd->GetXZWnd() ) {
2446 g_pParentWnd->GetXZWnd()->PositionView( position );
2448 if ( g_pParentWnd->GetYZWnd() ) {
2449 g_pParentWnd->GetYZWnd()->PositionView( position );
2454 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) {
2455 // cannot do this in a split window
2456 // do something else that the user may want here
2461 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2462 XYWnd_Focus( xywnd );
2466 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) {
2467 // cannot do this in a split window
2468 // do something else that the user may want here
2473 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2474 xywnd->SetViewType( XY );
2475 XYWnd_Focus( xywnd );
2479 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) {
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->SetViewType( XZ );
2488 XYWnd_Focus( xywnd );
2492 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) {
2493 // cannot do this in a split window
2494 // do something else that the user may want here
2499 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2500 xywnd->SetViewType( YZ );
2501 XYWnd_Focus( xywnd );
2505 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) {
2506 // cannot do this in a split window
2507 // do something else that the user may want here
2512 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2513 if ( xywnd->GetViewType() == XY ) {
2514 xywnd->SetViewType( XZ );
2516 else if ( xywnd->GetViewType() == XZ ) {
2517 xywnd->SetViewType( YZ );
2520 xywnd->SetViewType( XY );
2522 XYWnd_Focus( xywnd );
2526 if ( g_pParentWnd->GetXYWnd() ) {
2527 g_pParentWnd->GetXYWnd()->SetScale( 1 );
2529 if ( g_pParentWnd->GetXZWnd() ) {
2530 g_pParentWnd->GetXZWnd()->SetScale( 1 );
2532 if ( g_pParentWnd->GetYZWnd() ) {
2533 g_pParentWnd->GetYZWnd()->SetScale( 1 );
2538 g_pParentWnd->ActiveXY()->ZoomIn();
2541 // NOTE: the zoom out factor is 4/5, we could think about customizing it
2542 // we don't go below a zoom factor corresponding to 10% of the max world size
2543 // (this has to be computed against the window size)
2545 g_pParentWnd->ActiveXY()->ZoomOut();
2550 void ToggleShowCrosshair(){
2551 g_xywindow_globals_private.g_bCrossHairs ^= 1;
2552 XY_UpdateAllWindows();
2555 void ToggleShowSizeInfo(){
2556 g_xywindow_globals_private.m_bSizePaint = !g_xywindow_globals_private.m_bSizePaint;
2557 XY_UpdateAllWindows();
2560 void ToggleShowGrid(){
2561 g_xywindow_globals_private.d_showgrid = !g_xywindow_globals_private.d_showgrid;
2562 XY_UpdateAllWindows();
2565 ToggleShown g_xy_top_shown( true );
2567 void XY_Top_Shown_Construct( ui::Window parent ){
2568 g_xy_top_shown.connect( parent );
2571 ToggleShown g_yz_side_shown( false );
2573 void YZ_Side_Shown_Construct( ui::Window parent ){
2574 g_yz_side_shown.connect( parent );
2577 ToggleShown g_xz_front_shown( false );
2579 void XZ_Front_Shown_Construct( ui::Window parent ){
2580 g_xz_front_shown.connect( parent );
2584 class EntityClassMenu : public ModuleObserver
2586 std::size_t m_unrealised;
2588 EntityClassMenu() : m_unrealised( 1 ){
2591 if ( --m_unrealised == 0 ) {
2595 if ( ++m_unrealised == 1 ) {
2596 if ( XYWnd::m_mnuDrop ) {
2597 XYWnd::m_mnuDrop.destroy();
2598 XYWnd::m_mnuDrop = ui::Menu(ui::null);
2604 EntityClassMenu g_EntityClassMenu;
2609 void ShowNamesToggle(){
2610 GlobalEntityCreator().setShowNames( !GlobalEntityCreator().getShowNames() );
2611 XY_UpdateAllWindows();
2613 typedef FreeCaller<void(), ShowNamesToggle> ShowNamesToggleCaller;
2614 void ShowNamesExport( const Callback<void(bool)> & importer ){
2615 importer( GlobalEntityCreator().getShowNames() );
2617 typedef FreeCaller<void(const Callback<void(bool)> &), ShowNamesExport> ShowNamesExportCaller;
2619 void ShowAnglesToggle(){
2620 GlobalEntityCreator().setShowAngles( !GlobalEntityCreator().getShowAngles() );
2621 XY_UpdateAllWindows();
2623 typedef FreeCaller<void(), ShowAnglesToggle> ShowAnglesToggleCaller;
2624 void ShowAnglesExport( const Callback<void(bool)> & importer ){
2625 importer( GlobalEntityCreator().getShowAngles() );
2627 typedef FreeCaller<void(const Callback<void(bool)> &), ShowAnglesExport> ShowAnglesExportCaller;
2629 void ShowBlocksToggle(){
2630 g_xywindow_globals_private.show_blocks ^= 1;
2631 XY_UpdateAllWindows();
2633 typedef FreeCaller<void(), ShowBlocksToggle> ShowBlocksToggleCaller;
2634 void ShowBlocksExport( const Callback<void(bool)> & importer ){
2635 importer( g_xywindow_globals_private.show_blocks );
2637 typedef FreeCaller<void(const Callback<void(bool)> &), ShowBlocksExport> ShowBlocksExportCaller;
2639 void ShowCoordinatesToggle(){
2640 g_xywindow_globals_private.show_coordinates ^= 1;
2641 XY_UpdateAllWindows();
2643 typedef FreeCaller<void(), ShowCoordinatesToggle> ShowCoordinatesToggleCaller;
2644 void ShowCoordinatesExport( const Callback<void(bool)> & importer ){
2645 importer( g_xywindow_globals_private.show_coordinates );
2647 typedef FreeCaller<void(const Callback<void(bool)> &), ShowCoordinatesExport> ShowCoordinatesExportCaller;
2649 void ShowOutlineToggle(){
2650 g_xywindow_globals_private.show_outline ^= 1;
2651 XY_UpdateAllWindows();
2653 typedef FreeCaller<void(), ShowOutlineToggle> ShowOutlineToggleCaller;
2654 void ShowOutlineExport( const Callback<void(bool)> & importer ){
2655 importer( g_xywindow_globals_private.show_outline );
2657 typedef FreeCaller<void(const Callback<void(bool)> &), ShowOutlineExport> ShowOutlineExportCaller;
2659 void ShowAxesToggle(){
2660 g_xywindow_globals_private.show_axis ^= 1;
2661 XY_UpdateAllWindows();
2663 typedef FreeCaller<void(), ShowAxesToggle> ShowAxesToggleCaller;
2664 void ShowAxesExport( const Callback<void(bool)> & importer ){
2665 importer( g_xywindow_globals_private.show_axis );
2667 typedef FreeCaller<void(const Callback<void(bool)> &), ShowAxesExport> ShowAxesExportCaller;
2669 void ShowWorkzoneToggle(){
2670 g_xywindow_globals_private.d_show_work ^= 1;
2671 XY_UpdateAllWindows();
2673 typedef FreeCaller<void(), ShowWorkzoneToggle> ShowWorkzoneToggleCaller;
2674 void ShowWorkzoneExport( const Callback<void(bool)> & importer ){
2675 importer( g_xywindow_globals_private.d_show_work );
2677 typedef FreeCaller<void(const Callback<void(bool)> &), ShowWorkzoneExport> ShowWorkzoneExportCaller;
2679 ShowNamesExportCaller g_show_names_caller;
2680 Callback<void(const Callback<void(bool)> &)> g_show_names_callback( g_show_names_caller );
2681 ToggleItem g_show_names( g_show_names_callback );
2683 ShowAnglesExportCaller g_show_angles_caller;
2684 Callback<void(const Callback<void(bool)> &)> g_show_angles_callback( g_show_angles_caller );
2685 ToggleItem g_show_angles( g_show_angles_callback );
2687 ShowBlocksExportCaller g_show_blocks_caller;
2688 Callback<void(const Callback<void(bool)> &)> g_show_blocks_callback( g_show_blocks_caller );
2689 ToggleItem g_show_blocks( g_show_blocks_callback );
2691 ShowCoordinatesExportCaller g_show_coordinates_caller;
2692 Callback<void(const Callback<void(bool)> &)> g_show_coordinates_callback( g_show_coordinates_caller );
2693 ToggleItem g_show_coordinates( g_show_coordinates_callback );
2695 ShowOutlineExportCaller g_show_outline_caller;
2696 Callback<void(const Callback<void(bool)> &)> g_show_outline_callback( g_show_outline_caller );
2697 ToggleItem g_show_outline( g_show_outline_callback );
2699 ShowAxesExportCaller g_show_axes_caller;
2700 Callback<void(const Callback<void(bool)> &)> g_show_axes_callback( g_show_axes_caller );
2701 ToggleItem g_show_axes( g_show_axes_callback );
2703 ShowWorkzoneExportCaller g_show_workzone_caller;
2704 Callback<void(const Callback<void(bool)> &)> g_show_workzone_callback( g_show_workzone_caller );
2705 ToggleItem g_show_workzone( g_show_workzone_callback );
2707 void XYShow_registerCommands(){
2708 GlobalToggles_insert( "ShowAngles", ShowAnglesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_angles ) );
2709 GlobalToggles_insert( "ShowNames", ShowNamesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_names ) );
2710 GlobalToggles_insert( "ShowBlocks", ShowBlocksToggleCaller(), ToggleItem::AddCallbackCaller( g_show_blocks ) );
2711 GlobalToggles_insert( "ShowCoordinates", ShowCoordinatesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_coordinates ) );
2712 GlobalToggles_insert( "ShowWindowOutline", ShowOutlineToggleCaller(), ToggleItem::AddCallbackCaller( g_show_outline ) );
2713 GlobalToggles_insert( "ShowAxes", ShowAxesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_axes ) );
2714 GlobalToggles_insert( "ShowWorkzone", ShowWorkzoneToggleCaller(), ToggleItem::AddCallbackCaller( g_show_workzone ) );
2717 void XYWnd_registerShortcuts(){
2718 command_connect_accelerator( "ToggleCrosshairs" );
2719 command_connect_accelerator( "ToggleSizePaint" );
2724 void Orthographic_constructPreferences( PreferencesPage& page ){
2725 page.appendCheckBox( "", "Solid selection boxes", g_xywindow_globals.m_bNoStipple );
2726 page.appendCheckBox( "", "Display size info", g_xywindow_globals_private.m_bSizePaint );
2727 page.appendCheckBox( "", "Chase mouse during drags", g_xywindow_globals_private.m_bChaseMouse );
2728 page.appendCheckBox( "", "Update views on camera move", g_xywindow_globals_private.m_bCamXYUpdate );
2730 void Orthographic_constructPage( PreferenceGroup& group ){
2731 PreferencesPage page( group.createPage( "Orthographic", "Orthographic View Preferences" ) );
2732 Orthographic_constructPreferences( page );
2734 void Orthographic_registerPreferencesPage(){
2735 PreferencesDialog_addSettingsPage( makeCallbackF(Orthographic_constructPage) );
2738 void Clipper_constructPreferences( PreferencesPage& page ){
2739 page.appendCheckBox( "", "Clipper tool uses caulk", g_clip_useCaulk );
2741 void Clipper_constructPage( PreferenceGroup& group ){
2742 PreferencesPage page( group.createPage( "Clipper", "Clipper Tool Settings" ) );
2743 Clipper_constructPreferences( page );
2745 void Clipper_registerPreferencesPage(){
2746 PreferencesDialog_addSettingsPage( makeCallbackF(Clipper_constructPage) );
2750 #include "preferencesystem.h"
2751 #include "stringio.h"
2754 struct ToggleShown_Bool {
2755 static void Export(const ToggleShown &self, const Callback<void(bool)> &returnz) {
2756 returnz(self.active());
2759 static void Import(ToggleShown &self, bool value) {
2765 void XYWindow_Construct(){
2766 GlobalCommands_insert( "ToggleCrosshairs", makeCallbackF(ToggleShowCrosshair), Accelerator( 'X', (GdkModifierType)GDK_SHIFT_MASK ) );
2767 GlobalCommands_insert( "ToggleSizePaint", makeCallbackF(ToggleShowSizeInfo), Accelerator( 'J' ) );
2768 GlobalCommands_insert( "ToggleGrid", makeCallbackF(ToggleShowGrid), Accelerator( '0' ) );
2770 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 ) ) );
2771 GlobalToggles_insert( "ToggleSideView", ToggleShown::ToggleCaller( g_yz_side_shown ), ToggleItem::AddCallbackCaller( g_yz_side_shown.m_item ) );
2772 GlobalToggles_insert( "ToggleFrontView", ToggleShown::ToggleCaller( g_xz_front_shown ), ToggleItem::AddCallbackCaller( g_xz_front_shown.m_item ) );
2773 GlobalCommands_insert( "NextView", makeCallbackF(XY_Next), Accelerator( GDK_KEY_Tab, (GdkModifierType)GDK_CONTROL_MASK ) ); // fixme: doesn't show its shortcut
2774 GlobalCommands_insert( "ZoomIn", makeCallbackF(XY_ZoomIn), Accelerator( GDK_KEY_Delete ) );
2775 GlobalCommands_insert( "ZoomOut", makeCallbackF(XY_ZoomOut), Accelerator( GDK_KEY_Insert ) );
2776 GlobalCommands_insert( "ViewTop", makeCallbackF(XY_Top), Accelerator( GDK_KEY_KP_Home ) );
2777 GlobalCommands_insert( "ViewSide", makeCallbackF(XY_Side), Accelerator( GDK_KEY_KP_Page_Down ) );
2778 GlobalCommands_insert( "ViewFront", makeCallbackF(XY_Front), Accelerator( GDK_KEY_KP_End ) );
2779 GlobalCommands_insert( "Zoom100", makeCallbackF(XY_Zoom100) );
2780 GlobalCommands_insert( "CenterXYView", makeCallbackF(XY_Focus), Accelerator( GDK_KEY_Tab, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
2782 GlobalPreferenceSystem().registerPreference( "ClipCaulk", make_property_string( g_clip_useCaulk ) );
2784 GlobalPreferenceSystem().registerPreference( "NewRightClick", make_property_string( g_xywindow_globals.m_bRightClick ) );
2785 GlobalPreferenceSystem().registerPreference( "ImprovedWheelZoom", make_property_string( g_xywindow_globals.m_bImprovedWheelZoom ) );
2786 GlobalPreferenceSystem().registerPreference( "ChaseMouse", make_property_string( g_xywindow_globals_private.m_bChaseMouse ) );
2787 GlobalPreferenceSystem().registerPreference( "SizePainting", make_property_string( g_xywindow_globals_private.m_bSizePaint ) );
2788 GlobalPreferenceSystem().registerPreference( "ShowCrosshair", make_property_string( g_xywindow_globals_private.g_bCrossHairs ) );
2789 GlobalPreferenceSystem().registerPreference( "NoStipple", make_property_string( g_xywindow_globals.m_bNoStipple ) );
2790 GlobalPreferenceSystem().registerPreference( "SI_ShowCoords", make_property_string( g_xywindow_globals_private.show_coordinates ) );
2791 GlobalPreferenceSystem().registerPreference( "SI_ShowOutlines", make_property_string( g_xywindow_globals_private.show_outline ) );
2792 GlobalPreferenceSystem().registerPreference( "SI_ShowAxis", make_property_string( g_xywindow_globals_private.show_axis ) );
2793 GlobalPreferenceSystem().registerPreference( "CamXYUpdate", make_property_string( g_xywindow_globals_private.m_bCamXYUpdate ) );
2794 GlobalPreferenceSystem().registerPreference( "ShowWorkzone", make_property_string( g_xywindow_globals_private.d_show_work ) );
2796 GlobalPreferenceSystem().registerPreference( "SI_AxisColors0", make_property_string( g_xywindow_globals.AxisColorX ) );
2797 GlobalPreferenceSystem().registerPreference( "SI_AxisColors1", make_property_string( g_xywindow_globals.AxisColorY ) );
2798 GlobalPreferenceSystem().registerPreference( "SI_AxisColors2", make_property_string( g_xywindow_globals.AxisColorZ ) );
2799 GlobalPreferenceSystem().registerPreference( "SI_Colors1", make_property_string( g_xywindow_globals.color_gridback ) );
2800 GlobalPreferenceSystem().registerPreference( "SI_Colors2", make_property_string( g_xywindow_globals.color_gridminor ) );
2801 GlobalPreferenceSystem().registerPreference( "SI_Colors3", make_property_string( g_xywindow_globals.color_gridmajor ) );
2802 GlobalPreferenceSystem().registerPreference( "SI_Colors6", make_property_string( g_xywindow_globals.color_gridblock ) );
2803 GlobalPreferenceSystem().registerPreference( "SI_Colors7", make_property_string( g_xywindow_globals.color_gridtext ) );
2804 GlobalPreferenceSystem().registerPreference( "SI_Colors8", make_property_string( g_xywindow_globals.color_brushes ) );
2805 GlobalPreferenceSystem().registerPreference( "SI_Colors14", make_property_string( g_xywindow_globals.color_gridmajor_alt ) );
2808 GlobalPreferenceSystem().registerPreference( "XZVIS", make_property_string<ToggleShown_Bool>( g_xz_front_shown ) );
2809 GlobalPreferenceSystem().registerPreference( "YZVIS", make_property_string<ToggleShown_Bool>( g_yz_side_shown ) );
2811 Orthographic_registerPreferencesPage();
2812 Clipper_registerPreferencesPage();
2814 XYWnd::captureStates();
2815 GlobalEntityClassManager().attach( g_EntityClassMenu );
2818 void XYWindow_Destroy(){
2819 GlobalEntityClassManager().detach( g_EntityClassMenu );
2820 XYWnd::releaseStates();