2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 // Leonardo Zide (leo@lokigames.com)
32 #include "debugging/debugging.h"
39 #include "ifilesystem.h"
42 #include "gtkutil/messagebox.h"
44 #include <uilib/uilib.h>
45 #include <gdk/gdkkeysyms.h>
47 #include "generic/callback.h"
48 #include "string/string.h"
49 #include "stream/stringstream.h"
52 #include "eclasslib.h"
54 #include "moduleobserver.h"
56 #include "gtkutil/menu.h"
57 #include "gtkutil/container.h"
58 #include "gtkutil/widget.h"
59 #include "gtkutil/glwidget.h"
60 #include "gtkutil/filechooser.h"
61 #include "gtkutil/cursor.h"
65 #include "brushmanip.h"
66 #include "selection.h"
68 #include "camwindow.h"
69 #include "texwindow.h"
70 #include "mainframe.h"
71 #include "preferences.h"
75 #include "windowobservers.h"
77 void LoadTextureRGBA( qtexture_t* q, unsigned char* pPixels, int nWidth, int nHeight );
80 extern bool g_brush_always_caulk;
86 Vector3 m_ptClip; // the 3d point
93 m_ptClip[0] = m_ptClip[1] = m_ptClip[2] = 0.0;
107 /*! Draw clip/path point with rasterized number label */
108 void Draw( int num, float scale );
109 /*! Draw clip/path point with rasterized string label */
110 void Draw( const char *label, float scale );
113 VIEWTYPE g_clip_viewtype;
114 bool g_bSwitch = true;
115 bool g_clip_useCaulk = false;
116 bool g_quick_clipper = false;
120 ClipPoint* g_pMovingClip = 0;
122 /* Drawing clip points */
123 void ClipPoint::Draw( int num, float scale ){
124 StringOutputStream label( 4 );
126 Draw( label.c_str(), scale );
129 void ClipPoint::Draw( const char *label, float scale ){
132 glColor3fv( vector3_to_array( g_xywindow_globals.color_clipper ) );
133 glBegin( GL_POINTS );
134 glVertex3fv( vector3_to_array( m_ptClip ) );
138 float offset = 2.0f / scale;
141 glRasterPos3f( m_ptClip[0] + offset, m_ptClip[1] + offset, m_ptClip[2] + offset );
142 glCallLists( GLsizei( strlen( label ) ), GL_UNSIGNED_BYTE, label );
145 float fDiff( float f1, float f2 ){
154 inline double ClipPoint_Intersect( const ClipPoint& clip, const Vector3& point, VIEWTYPE viewtype, float scale ){
155 int nDim1 = ( viewtype == YZ ) ? 1 : 0;
156 int nDim2 = ( viewtype == XY ) ? 1 : 2;
157 double screenDistanceSquared( vector2_length_squared( Vector2( fDiff( clip.m_ptClip[nDim1], point[nDim1] ) * scale, fDiff( clip.m_ptClip[nDim2], point[nDim2] ) * scale ) ) );
158 if ( screenDistanceSquared < 8 * 8 ) {
159 return screenDistanceSquared;
164 inline void ClipPoint_testSelect( ClipPoint& clip, const Vector3& point, VIEWTYPE viewtype, float scale, double& bestDistance, ClipPoint*& bestClip ){
166 double distance = ClipPoint_Intersect( clip, point, viewtype, scale );
167 if ( distance < bestDistance ) {
168 bestDistance = distance;
174 inline ClipPoint* GlobalClipPoints_Find( const Vector3& point, VIEWTYPE viewtype, float scale ){
175 double bestDistance = FLT_MAX;
176 ClipPoint* bestClip = 0;
177 ClipPoint_testSelect( g_Clip1, point, viewtype, scale, bestDistance, bestClip );
178 ClipPoint_testSelect( g_Clip2, point, viewtype, scale, bestDistance, bestClip );
179 ClipPoint_testSelect( g_Clip3, point, viewtype, scale, bestDistance, bestClip );
183 inline void GlobalClipPoints_Draw( float scale ){
185 if ( g_Clip1.Set() ) {
186 g_Clip1.Draw( 1, scale );
188 if ( g_Clip2.Set() ) {
189 g_Clip2.Draw( 2, scale );
191 if ( g_Clip3.Set() ) {
192 g_Clip3.Draw( 3, scale );
196 inline bool GlobalClipPoints_valid(){
197 return g_Clip1.Set() && g_Clip2.Set();
200 void PlanePointsFromClipPoints( Vector3 planepts[3], const AABB& bounds, int viewtype ){
201 ASSERT_MESSAGE( GlobalClipPoints_valid(), "clipper points not initialised" );
202 planepts[0] = g_Clip1.m_ptClip;
203 planepts[1] = g_Clip2.m_ptClip;
204 planepts[2] = g_Clip3.m_ptClip;
205 Vector3 maxs( vector3_added( bounds.origin, bounds.extents ) );
206 Vector3 mins( vector3_subtracted( bounds.origin, bounds.extents ) );
207 if ( !g_Clip3.Set() ) {
208 int n = ( viewtype == XY ) ? 2 : ( viewtype == YZ ) ? 0 : 1;
209 int x = ( n == 0 ) ? 1 : 0;
210 int y = ( n == 2 ) ? 1 : 2;
212 if ( n == 1 ) { // on viewtype XZ, flip clip points
213 planepts[0][n] = maxs[n];
214 planepts[1][n] = maxs[n];
215 planepts[2][x] = g_Clip1.m_ptClip[x];
216 planepts[2][y] = g_Clip1.m_ptClip[y];
217 planepts[2][n] = mins[n];
221 planepts[0][n] = mins[n];
222 planepts[1][n] = mins[n];
223 planepts[2][x] = g_Clip1.m_ptClip[x];
224 planepts[2][y] = g_Clip1.m_ptClip[y];
225 planepts[2][n] = maxs[n];
232 if ( !GlobalClipPoints_valid() ) {
233 planepts[0] = Vector3( 0, 0, 0 );
234 planepts[1] = Vector3( 0, 0, 0 );
235 planepts[2] = Vector3( 0, 0, 0 );
236 Scene_BrushSetClipPlane( GlobalSceneGraph(), Plane3( 0, 0, 0, 0 ) );
240 AABB bounds( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) );
241 PlanePointsFromClipPoints( planepts, bounds, g_clip_viewtype );
243 std::swap( planepts[0], planepts[1] );
245 Scene_BrushSetClipPlane( GlobalSceneGraph(), plane3_for_points( planepts[0], planepts[1], planepts[2] ) );
247 ClipperChangeNotify();
250 const char* Clip_getShader(){
251 return g_clip_useCaulk ? "textures/common/caulk" : TextureBrowser_GetSelectedShader( GlobalTextureBrowser() );
255 if ( ClipMode() && GlobalClipPoints_valid() ) {
257 AABB bounds( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) );
258 PlanePointsFromClipPoints( planepts, bounds, g_clip_viewtype );
259 Scene_BrushSplitByPlane( GlobalSceneGraph(), planepts[0], planepts[1], planepts[2], Clip_getShader(), ( !g_bSwitch ) ? eFront : eBack );
264 ClipperChangeNotify();
265 if( g_quick_clipper ){
266 g_quick_clipper = false;
273 if ( ClipMode() && GlobalClipPoints_valid() ) {
275 AABB bounds( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) );
276 PlanePointsFromClipPoints( planepts, bounds, g_clip_viewtype );
277 Scene_BrushSplitByPlane( GlobalSceneGraph(), planepts[0], planepts[1], planepts[2], Clip_getShader(), eFrontAndBack );
282 ClipperChangeNotify();
283 if( g_quick_clipper ){
284 g_quick_clipper = false;
291 g_bSwitch = !g_bSwitch;
293 ClipperChangeNotify();
296 void OnClipMode( bool enabled ){
301 if ( !enabled && g_pMovingClip ) {
306 ClipperChangeNotify();
310 return GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eClip;
313 void NewClipPoint( const Vector3& point ){
314 if ( g_Clip1.Set() == false ) {
315 g_Clip1.m_ptClip = point;
318 else if ( g_Clip2.Set() == false ) {
319 g_Clip2.m_ptClip = point;
322 else if ( g_Clip3.Set() == false ) {
323 g_Clip3.m_ptClip = point;
331 g_Clip1.m_ptClip = point;
336 ClipperChangeNotify();
341 struct xywindow_globals_private_t
345 // these are in the View > Show menu with Show coordinates
347 bool show_coordinates;
363 xywindow_globals_private_t() :
367 show_coordinates( false ),
369 show_outline( false ),
372 d_show_work( false ),
374 show_blocks( false ),
376 m_bCamXYUpdate( true ),
377 m_bChaseMouse( true ),
378 m_bSizePaint( true ),
380 g_bCrossHairs( false ){
385 xywindow_globals_t g_xywindow_globals;
386 xywindow_globals_private_t g_xywindow_globals_private;
388 const unsigned int RAD_NONE = 0x00;
389 const unsigned int RAD_SHIFT = 0x01;
390 const unsigned int RAD_ALT = 0x02;
391 const unsigned int RAD_CONTROL = 0x04;
392 const unsigned int RAD_PRESS = 0x08;
393 const unsigned int RAD_LBUTTON = 0x10;
394 const unsigned int RAD_MBUTTON = 0x20;
395 const unsigned int RAD_RBUTTON = 0x40;
397 inline ButtonIdentifier button_for_flags( unsigned int flags ){
398 if ( flags & RAD_LBUTTON ) {
401 if ( flags & RAD_RBUTTON ) {
402 return c_buttonRight;
404 if ( flags & RAD_MBUTTON ) {
405 return c_buttonMiddle;
407 return c_buttonInvalid;
410 inline ModifierFlags modifiers_for_flags( unsigned int flags ){
411 ModifierFlags modifiers = c_modifierNone;
412 if ( flags & RAD_SHIFT ) {
413 modifiers |= c_modifierShift;
415 if ( flags & RAD_CONTROL ) {
416 modifiers |= c_modifierControl;
418 if ( flags & RAD_ALT ) {
419 modifiers |= c_modifierAlt;
424 inline unsigned int buttons_for_button_and_modifiers( ButtonIdentifier button, ModifierFlags flags ){
425 unsigned int buttons = 0;
427 switch ( button.get() )
429 case ButtonEnumeration::INVALID: break;
430 case ButtonEnumeration::LEFT: buttons |= RAD_LBUTTON; break;
431 case ButtonEnumeration::MIDDLE: buttons |= RAD_MBUTTON; break;
432 case ButtonEnumeration::RIGHT: buttons |= RAD_RBUTTON; break;
435 if ( bitfield_enabled( flags, c_modifierControl ) ) {
436 buttons |= RAD_CONTROL;
439 if ( bitfield_enabled( flags, c_modifierShift ) ) {
440 buttons |= RAD_SHIFT;
443 if ( bitfield_enabled( flags, c_modifierAlt ) ) {
450 inline unsigned int buttons_for_event_button( GdkEventButton* event ){
451 unsigned int flags = 0;
453 switch ( event->button )
455 case 1: flags |= RAD_LBUTTON; break;
456 case 2: flags |= RAD_MBUTTON; break;
457 case 3: flags |= RAD_RBUTTON; break;
460 if ( ( event->state & GDK_CONTROL_MASK ) != 0 ) {
461 flags |= RAD_CONTROL;
464 if ( ( event->state & GDK_SHIFT_MASK ) != 0 ) {
468 if ( ( event->state & GDK_MOD1_MASK ) != 0 ) {
475 inline unsigned int buttons_for_state( guint state ){
476 unsigned int flags = 0;
478 if ( ( state & GDK_BUTTON1_MASK ) != 0 ) {
479 flags |= RAD_LBUTTON;
482 if ( ( state & GDK_BUTTON2_MASK ) != 0 ) {
483 flags |= RAD_MBUTTON;
486 if ( ( state & GDK_BUTTON3_MASK ) != 0 ) {
487 flags |= RAD_RBUTTON;
490 if ( ( state & GDK_CONTROL_MASK ) != 0 ) {
491 flags |= RAD_CONTROL;
494 if ( ( state & GDK_SHIFT_MASK ) != 0 ) {
498 if ( ( state & GDK_MOD1_MASK ) != 0 ) {
506 void XYWnd::SetScale( float f ){
510 XYWnd_Update( *this );
513 void XYWnd::ZoomIn(){
514 float max_scale = 64;
515 float scale = Scale() * 5.0f / 4.0f;
516 if ( scale > max_scale ) {
517 if ( Scale() != max_scale ) {
518 SetScale( max_scale );
528 // NOTE: the zoom out factor is 4/5, we could think about customizing it
529 // we don't go below a zoom factor corresponding to 10% of the max world size
530 // (this has to be computed against the window size)
531 void XYWnd::ZoomOut(){
532 float min_scale = MIN( Width(), Height() ) / ( 1.1f * ( g_MaxWorldCoord - g_MinWorldCoord ) );
533 float scale = Scale() * 4.0f / 5.0f;
534 if ( scale < min_scale ) {
535 if ( Scale() != min_scale ) {
536 SetScale( min_scale );
545 void XYWnd::ZoomInWithMouse( int pointx, int pointy ){
546 float old_scale = Scale();
548 if ( g_xywindow_globals.m_bImprovedWheelZoom ) {
549 float scale_diff = 1.0 / old_scale - 1.0 / Scale();
550 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
551 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
552 Vector3 origin = GetOrigin();
553 origin[nDim1] += scale_diff * (pointx - 0.5 * Width());
554 origin[nDim2] -= scale_diff * (pointy - 0.5 * Height());
559 void XYWnd::Redraw() {
560 if ( glwidget_make_current( m_gl_widget ) != FALSE ) {
561 if ( Map_Valid( g_map ) && ScreenUpdates_Enabled() ) {
562 GlobalOpenGL_debugAssertNoErrors();
564 GlobalOpenGL_debugAssertNoErrors();
566 m_XORRectangle.set( rectangle_t() );
568 glwidget_swap_buffers( m_gl_widget );
572 VIEWTYPE GlobalXYWnd_getCurrentViewType(){
573 ASSERT_NOTNULL( g_pParentWnd );
574 ASSERT_NOTNULL( g_pParentWnd->ActiveXY() );
575 return g_pParentWnd->ActiveXY()->GetViewType();
578 // =============================================================================
581 ui::Menu XYWnd::m_mnuDrop(ui::null);
583 // this is disabled, and broken
584 // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=394
588 width = g_pParentWnd->ActiveXY()->Width();
589 height = g_pParentWnd->ActiveXY()->Height();
591 const char* filename;
593 filename = ui::file_dialog( MainFrame_getWindow( ), FALSE, "Save Image", 0, FILTER_BMP );
598 g_pParentWnd->ActiveXY()->MakeCurrent();
599 img = (unsigned char*)malloc( width * height * 3 );
600 glReadPixels( 0,0,width,height,GL_RGB,GL_UNSIGNED_BYTE,img );
603 fp = fopen( filename, "wb" );
606 unsigned long cmap, bfSize;
610 bfSize = 54 + width * height * 3;
612 long byteswritten = 0;
613 long pixoff = 54 + cmap * 4;
615 char m1 = 'B', m2 = 'M';
616 fwrite( &m1, 1, 1, fp ); byteswritten++; // B
617 fwrite( &m2, 1, 1, fp ); byteswritten++; // M
618 fwrite( &bfSize, 4, 1, fp ); byteswritten += 4; // bfSize
619 fwrite( &res, 2, 1, fp ); byteswritten += 2; // bfReserved1
620 fwrite( &res, 2, 1, fp ); byteswritten += 2; // bfReserved2
621 fwrite( &pixoff, 4, 1, fp ); byteswritten += 4; // bfOffBits
623 unsigned long biSize = 40, compress = 0, size = 0;
625 unsigned short planes = 1;
626 fwrite( &biSize, 4, 1, fp ); byteswritten += 4; // biSize
627 fwrite( &width, 4, 1, fp ); byteswritten += 4; // biWidth
628 fwrite( &height, 4, 1, fp ); byteswritten += 4; // biHeight
629 fwrite( &planes, 2, 1, fp ); byteswritten += 2; // biPlanes
630 fwrite( &bits, 2, 1, fp ); byteswritten += 2; // biBitCount
631 fwrite( &compress, 4, 1, fp ); byteswritten += 4; // biCompression
632 fwrite( &size, 4, 1, fp ); byteswritten += 4; // biSizeImage
633 fwrite( &pixels, 4, 1, fp ); byteswritten += 4; // biXPelsPerMeter
634 fwrite( &pixels, 4, 1, fp ); byteswritten += 4; // biYPelsPerMeter
635 fwrite( &cmap, 4, 1, fp ); byteswritten += 4; // biClrUsed
636 fwrite( &cmap, 4, 1, fp ); byteswritten += 4; // biClrImportant
638 unsigned long widthDW = ( ( ( width * 24 ) + 31 ) / 32 * 4 );
639 long row, row_size = width * 3;
640 for ( row = 0; row < height; row++ )
642 unsigned char* buf = img + row * row_size;
646 for ( col = 0; col < row_size; col += 3 )
648 putc( buf[col + 2], fp );
649 putc( buf[col + 1], fp );
650 putc( buf[col], fp );
652 byteswritten += row_size;
655 for ( count = row_size; count < widthDW; count++ )
657 putc( 0, fp ); // dummy
672 Timer g_chasemouse_timer;
674 void XYWnd::ChaseMouse(){
675 float multiplier = g_chasemouse_timer.elapsed_msec() / 10.0f;
676 Scroll( float_to_integer( multiplier * m_chasemouse_delta_x ), float_to_integer( multiplier * -m_chasemouse_delta_y ) );
678 //globalOutputStream() << "chasemouse: multiplier=" << multiplier << " x=" << m_chasemouse_delta_x << " y=" << m_chasemouse_delta_y << '\n';
680 XY_MouseMoved( m_chasemouse_current_x, m_chasemouse_current_y, getButtonState() );
681 g_chasemouse_timer.start();
684 gboolean xywnd_chasemouse( gpointer data ){
685 reinterpret_cast<XYWnd*>( data )->ChaseMouse();
689 inline const int& min_int( const int& left, const int& right ){
690 return std::min( left, right );
693 bool XYWnd::chaseMouseMotion( int pointx, int pointy ){
694 m_chasemouse_delta_x = 0;
695 m_chasemouse_delta_y = 0;
697 if ( g_xywindow_globals_private.m_bChaseMouse && getButtonState() == RAD_LBUTTON ) {
698 const int epsilon = 16;
700 if ( pointx < epsilon ) {
701 m_chasemouse_delta_x = std::max( pointx, 0 ) - epsilon;
703 else if ( ( pointx - m_nWidth ) > -epsilon ) {
704 m_chasemouse_delta_x = min_int( ( pointx - m_nWidth ), 0 ) + epsilon;
707 if ( pointy < epsilon ) {
708 m_chasemouse_delta_y = std::max( pointy, 0 ) - epsilon;
710 else if ( ( pointy - m_nHeight ) > -epsilon ) {
711 m_chasemouse_delta_y = min_int( ( pointy - m_nHeight ), 0 ) + epsilon;
714 if ( m_chasemouse_delta_y != 0 || m_chasemouse_delta_x != 0 ) {
715 //globalOutputStream() << "chasemouse motion: x=" << pointx << " y=" << pointy << "... ";
716 m_chasemouse_current_x = pointx;
717 m_chasemouse_current_y = pointy;
718 if ( m_chasemouse_handler == 0 ) {
719 //globalOutputStream() << "chasemouse timer start... ";
720 g_chasemouse_timer.start();
721 m_chasemouse_handler = g_idle_add( xywnd_chasemouse, this );
727 if ( m_chasemouse_handler != 0 ) {
728 //globalOutputStream() << "chasemouse cancel\n";
729 g_source_remove( m_chasemouse_handler );
730 m_chasemouse_handler = 0;
736 if ( m_chasemouse_handler != 0 ) {
737 //globalOutputStream() << "chasemouse cancel\n";
738 g_source_remove( m_chasemouse_handler );
739 m_chasemouse_handler = 0;
745 // =============================================================================
747 Shader* XYWnd::m_state_selected = 0;
749 void xy_update_xor_rectangle( XYWnd& self, rect_t area ){
750 if ( self.GetWidget().visible() ) {
751 rectangle_t rect = rectangle_from_area( area.min, area.max, self.Width(), self.Height() );
752 // int nDim1 = ( self.GetViewType() == YZ ) ? 1 : 0;
753 // int nDim2 = ( self.GetViewType() == XY ) ? 1 : 2;
754 // rect.x /= self.Scale();
755 // rect.y /= self.Scale();
756 // rect.w /= self.Scale();
757 // rect.h /= self.Scale();
758 // rect.x += self.GetOrigin()[nDim1];
759 // rect.y += self.GetOrigin()[nDim2];
760 self.m_XORRectangle.set( rect );
764 gboolean xywnd_button_press( ui::Widget widget, GdkEventButton* event, XYWnd* xywnd ){
765 if ( event->type == GDK_BUTTON_PRESS ) {
766 if( !xywnd->Active() ){
767 g_pParentWnd->SetActiveXY( xywnd );
770 xywnd->ButtonState_onMouseDown( buttons_for_event_button( event ) );
772 xywnd->onMouseDown( WindowVector( event->x, event->y ), button_for_button( event->button ), modifiers_for_state( event->state ) );
777 gboolean xywnd_button_release( ui::Widget widget, GdkEventButton* event, XYWnd* xywnd ){
778 if ( event->type == GDK_BUTTON_RELEASE ) {
779 xywnd->XY_MouseUp( static_cast<int>( event->x ), static_cast<int>( event->y ), buttons_for_event_button( event ) );
781 xywnd->ButtonState_onMouseUp( buttons_for_event_button( event ) );
786 gboolean xywnd_focus_in( ui::Widget widget, GdkEventFocus* event, XYWnd* xywnd ){
787 if ( event->type == GDK_FOCUS_CHANGE ) {
789 if( !xywnd->Active() ){
790 g_pParentWnd->SetActiveXY( xywnd );
797 void xywnd_motion( gdouble x, gdouble y, guint state, void* data ){
798 if ( reinterpret_cast<XYWnd*>( data )->chaseMouseMotion( static_cast<int>( x ), static_cast<int>( y ) ) ) {
801 reinterpret_cast<XYWnd*>( data )->XY_MouseMoved( static_cast<int>( x ), static_cast<int>( y ), buttons_for_state( state ) );
804 gboolean xywnd_wheel_scroll( ui::Widget widget, GdkEventScroll* event, XYWnd* xywnd ){
805 if( !xywnd->Active() ){
806 g_pParentWnd->SetActiveXY( xywnd );
808 if ( event->direction == GDK_SCROLL_UP ) {
809 xywnd->ZoomInWithMouse( (int)event->x, (int)event->y );
811 else if ( event->direction == GDK_SCROLL_DOWN ) {
817 gboolean xywnd_size_allocate( ui::Widget widget, GtkAllocation* allocation, XYWnd* xywnd ){
818 xywnd->m_nWidth = allocation->width;
819 xywnd->m_nHeight = allocation->height;
820 xywnd->updateProjection();
821 xywnd->m_window_observer->onSizeChanged( xywnd->Width(), xywnd->Height() );
825 gboolean xywnd_expose( ui::Widget widget, GdkEventExpose* event, XYWnd* xywnd ){
830 void XYWnd_CameraMoved( XYWnd& xywnd ){
831 if ( g_xywindow_globals_private.m_bCamXYUpdate ) {
832 XYWnd_Update( xywnd );
837 m_gl_widget( glwidget_new( FALSE ) ),
838 m_deferredDraw( WidgetQueueDrawCaller( m_gl_widget ) ),
839 m_deferred_motion( xywnd_motion, this ),
840 m_parent( ui::null ),
841 m_window_observer( NewWindowObserver() ),
842 m_XORRectangle( m_gl_widget ),
843 m_chasemouse_handler( 0 ){
848 m_bNewBrushDrag = false;
849 m_move_started = false;
850 m_zoom_started = false;
861 m_backgroundActivated = false;
868 m_entityCreate = false;
870 m_mnuDrop = ui::Menu(ui::null);
872 GlobalWindowObservers_add( m_window_observer );
873 GlobalWindowObservers_connectWidget( m_gl_widget );
875 m_window_observer->setRectangleDrawCallback( ReferenceCaller<XYWnd, void(rect_t), xy_update_xor_rectangle>( *this ) );
876 m_window_observer->setView( m_view );
878 g_object_ref( m_gl_widget._handle );
880 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 );
881 gtk_widget_set_can_focus( m_gl_widget, true );
883 m_sizeHandler = m_gl_widget.connect( "size_allocate", G_CALLBACK( xywnd_size_allocate ), this );
884 m_exposeHandler = m_gl_widget.on_render( G_CALLBACK( xywnd_expose ), this );
886 m_gl_widget.connect( "button_press_event", G_CALLBACK( xywnd_button_press ), this );
887 m_gl_widget.connect( "button_release_event", G_CALLBACK( xywnd_button_release ), this );
888 m_gl_widget.connect( "focus_in_event", G_CALLBACK( xywnd_focus_in ), this ); //works only in floating views layout
889 m_gl_widget.connect( "motion_notify_event", G_CALLBACK( DeferredMotion::gtk_motion ), &m_deferred_motion );
891 m_gl_widget.connect( "scroll_event", G_CALLBACK( xywnd_wheel_scroll ), this );
893 Map_addValidCallback( g_map, DeferredDrawOnMapValidChangedCaller( m_deferredDraw ) );
895 // This reconstruct=false argument is used to avoid a circular dependency
896 // between modelview and projection initialization and a valgrind complaint
897 updateProjection( false );
898 updateModelview( false );
899 m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight );
901 AddSceneChangeCallback( ReferenceCaller<XYWnd, void(), &XYWnd_Update>( *this ) );
902 AddCameraMovedCallback( ReferenceCaller<XYWnd, void(), &XYWnd_CameraMoved>( *this ) );
904 PressedButtons_connect( g_pressedButtons, m_gl_widget );
906 onMouseDown.connectLast( makeSignalHandler3( MouseDownCaller(), *this ) );
914 m_mnuDrop = ui::Menu(ui::null);
917 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_sizeHandler );
918 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_exposeHandler );
922 m_window_observer->release();
925 void XYWnd::captureStates(){
926 m_state_selected = GlobalShaderCache().capture( "$XY_OVERLAY" );
929 void XYWnd::releaseStates(){
930 GlobalShaderCache().release( "$XY_OVERLAY" );
933 const Vector3& XYWnd::GetOrigin(){
937 void XYWnd::SetOrigin( const Vector3& origin ){
942 void XYWnd::Scroll( int x, int y ){
943 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
944 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
945 m_vOrigin[nDim1] += x / m_fScale;
946 m_vOrigin[nDim2] += y / m_fScale;
951 unsigned int Clipper_buttons(){
955 unsigned int Clipper_quick_buttons(){
956 return RAD_LBUTTON | RAD_CONTROL;
959 void XYWnd::DropClipPoint( int pointx, int pointy ){
962 XY_ToPoint( pointx, pointy, point );
965 Select_GetMid( mid );
966 g_clip_viewtype = static_cast<VIEWTYPE>( GetViewType() );
967 const int nDim = ( g_clip_viewtype == YZ ) ? 0 : ( ( g_clip_viewtype == XZ ) ? 1 : 2 );
968 point[nDim] = mid[nDim];
969 vector3_snap( point, GetSnapGridSize() );
970 NewClipPoint( point );
973 void XYWnd::Clipper_OnLButtonDown( int x, int y ){
974 Vector3 mousePosition;
975 XY_ToPoint( x, y, mousePosition );
976 g_pMovingClip = GlobalClipPoints_Find( mousePosition, (VIEWTYPE)m_viewType, m_fScale );
977 if ( !g_pMovingClip ) {
978 DropClipPoint( x, y );
982 void XYWnd::Clipper_OnLButtonUp( int x, int y ){
983 if ( g_pMovingClip ) {
988 void XYWnd::Clipper_OnMouseMoved( int x, int y ){
989 if ( g_pMovingClip ) {
990 XY_ToPoint( x, y, g_pMovingClip->m_ptClip );
991 XY_SnapToGrid( g_pMovingClip->m_ptClip );
993 ClipperChangeNotify();
997 void XYWnd::Clipper_Crosshair_OnMouseMoved( int x, int y ){
998 Vector3 mousePosition;
999 XY_ToPoint( x, y, mousePosition );
1000 if ( ClipMode() && GlobalClipPoints_Find( mousePosition, (VIEWTYPE)m_viewType, m_fScale ) != 0 ) {
1001 set_cursor ( m_gl_widget, GDK_CROSSHAIR );
1005 default_cursor( m_gl_widget );
1009 void XYWnd::SetCustomPivotOrigin( int pointx, int pointy ){
1011 XY_ToPoint( pointx, pointy, point );
1012 VIEWTYPE viewtype = static_cast<VIEWTYPE>( GetViewType() );
1013 const int nDim = ( viewtype == YZ ) ? 0 : ( ( viewtype == XZ ) ? 1 : 2 );
1014 //vector3_snap( point, GetSnapGridSize() );
1015 point[nDim] = 999999;
1017 GlobalSelectionSystem().setCustomPivotOrigin( point );
1018 SceneChangeNotify();
1021 unsigned int MoveCamera_buttons(){
1022 return RAD_CONTROL | ( g_glwindow_globals.m_nMouseType == ETwoButton ? RAD_RBUTTON : RAD_MBUTTON );
1025 void XYWnd_PositionCamera( XYWnd* xywnd, int x, int y, CamWnd& camwnd ){
1026 Vector3 origin( Camera_getOrigin( camwnd ) );
1027 xywnd->XY_ToPoint( x, y, origin );
1028 xywnd->XY_SnapToGrid( origin );
1029 Camera_setOrigin( camwnd, origin );
1032 unsigned int OrientCamera_buttons(){
1033 if ( g_glwindow_globals.m_nMouseType == ETwoButton ) {
1034 return RAD_RBUTTON | RAD_SHIFT | RAD_CONTROL;
1039 void XYWnd_OrientCamera( XYWnd* xywnd, int x, int y, CamWnd& camwnd ){
1040 Vector3 point = g_vector3_identity;
1041 xywnd->XY_ToPoint( x, y, point );
1042 xywnd->XY_SnapToGrid( point );
1043 vector3_subtract( point, Camera_getOrigin( camwnd ) );
1045 int n1 = ( xywnd->GetViewType() == XY ) ? 1 : 2;
1046 int n2 = ( xywnd->GetViewType() == YZ ) ? 1 : 0;
1047 int nAngle = ( xywnd->GetViewType() == XY ) ? CAMERA_YAW : CAMERA_PITCH;
1048 if ( point[n1] || point[n2] ) {
1049 Vector3 angles( Camera_getAngles( camwnd ) );
1050 angles[nAngle] = static_cast<float>( radians_to_degrees( atan2( point[n1], point[n2] ) ) );
1051 Camera_setAngles( camwnd, angles );
1055 unsigned int SetCustomPivotOrigin_buttons(){
1056 return RAD_MBUTTON | RAD_SHIFT;
1064 unsigned int NewBrushDrag_buttons(){
1068 void XYWnd::NewBrushDrag_Begin( int x, int y ){
1070 m_nNewBrushPressx = x;
1071 m_nNewBrushPressy = y;
1073 m_bNewBrushDrag = true;
1074 GlobalUndoSystem().start();
1077 void XYWnd::NewBrushDrag_End( int x, int y ){
1078 if ( m_NewBrushDrag != 0 ) {
1079 GlobalUndoSystem().finish( "brushDragNew" );
1083 void XYWnd::NewBrushDrag( int x, int y ){
1085 XY_ToPoint( m_nNewBrushPressx, m_nNewBrushPressy, mins );
1086 XY_SnapToGrid( mins );
1087 XY_ToPoint( x, y, maxs );
1088 XY_SnapToGrid( maxs );
1090 int nDim = ( m_viewType == XY ) ? 2 : ( m_viewType == YZ ) ? 0 : 1;
1092 mins[nDim] = float_snapped( Select_getWorkZone().d_work_min[nDim], GetSnapGridSize() );
1093 maxs[nDim] = float_snapped( Select_getWorkZone().d_work_max[nDim], GetSnapGridSize() );
1095 if ( maxs[nDim] <= mins[nDim] ) {
1096 maxs[nDim] = mins[nDim] + GetGridSize();
1099 for ( int i = 0 ; i < 3 ; i++ )
1101 if ( mins[i] == maxs[i] ) {
1102 return; // don't create a degenerate brush
1104 if ( mins[i] > maxs[i] ) {
1105 float temp = mins[i];
1111 if ( m_NewBrushDrag == 0 ) {
1112 NodeSmartReference node( GlobalBrushCreator().createBrush() );
1113 Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->insert( node );
1115 scene::Path brushpath( makeReference( GlobalSceneGraph().root() ) );
1116 brushpath.push( makeReference( *Map_GetWorldspawn( g_map ) ) );
1117 brushpath.push( makeReference( node.get() ) );
1118 selectPath( brushpath, true );
1120 m_NewBrushDrag = node.get_pointer();
1124 //Scene_BrushResize_Selected(GlobalSceneGraph(), aabb_for_minmax(mins, maxs), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()));
1125 Scene_BrushResize_Selected( GlobalSceneGraph(), aabb_for_minmax( mins, maxs ),
1126 g_brush_always_caulk ?
1127 "textures/common/caulk" : TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ) );
1130 void entitycreate_activated( ui::Widget item ){
1131 scene::Node* world_node = Map_FindWorldspawn( g_map );
1132 const char* entity_name = gtk_label_get_text( GTK_LABEL( gtk_bin_get_child(GTK_BIN( item )) ) );
1134 if ( !( world_node && string_equal( entity_name, "worldspawn" ) ) ) {
1135 g_pParentWnd->ActiveXY()->OnEntityCreate( entity_name );
1138 GlobalRadiant().m_pfnMessageBox( MainFrame_getWindow(),
1139 "There's already a worldspawn in your map!",
1146 void EntityClassMenu_addItem( ui::Menu menu, const char* name ){
1147 auto item = ui::MenuItem( name );
1148 item.connect( "activate", G_CALLBACK( entitycreate_activated ), item );
1150 menu_add_item( menu, item );
1153 class EntityClassMenuInserter : public EntityClassVisitor
1155 typedef std::pair<ui::Menu, CopiedString> MenuPair;
1156 typedef std::vector<MenuPair> MenuStack;
1158 CopiedString m_previous;
1160 EntityClassMenuInserter( ui::Menu menu ){
1161 m_stack.reserve( 2 );
1162 m_stack.push_back( MenuPair( menu, "" ) );
1164 ~EntityClassMenuInserter(){
1165 if ( !string_empty( m_previous.c_str() ) ) {
1166 addItem( m_previous.c_str(), "" );
1169 void visit( EntityClass* e ){
1170 ASSERT_MESSAGE( !string_empty( e->name() ), "entity-class has no name" );
1171 if ( !string_empty( m_previous.c_str() ) ) {
1172 addItem( m_previous.c_str(), e->name() );
1174 m_previous = e->name();
1176 void pushMenu( const CopiedString& name ){
1177 auto item = ui::MenuItem( name.c_str() );
1179 m_stack.back().first.add(item);
1181 auto submenu = ui::Menu(ui::New);
1182 gtk_menu_item_set_submenu( item, submenu );
1184 m_stack.push_back( MenuPair( submenu, name ) );
1189 void addItem( const char* name, const char* next ){
1190 const char* underscore = strchr( name, '_' );
1192 if ( underscore != 0 && underscore != name ) {
1193 bool nextEqual = string_equal_n( name, next, ( underscore + 1 ) - name );
1194 const char* parent = m_stack.back().second.c_str();
1196 if ( !string_empty( parent )
1197 && string_length( parent ) == std::size_t( underscore - name )
1198 && string_equal_n( name, parent, underscore - name ) ) { // this is a child
1200 else if ( nextEqual ) {
1201 if ( m_stack.size() == 2 ) {
1204 pushMenu( CopiedString( StringRange( name, underscore ) ) );
1206 else if ( m_stack.size() == 2 ) {
1210 else if ( m_stack.size() == 2 ) {
1214 EntityClassMenu_addItem( m_stack.back().first, name );
1218 void XYWnd::OnContextMenu(){
1219 if ( g_xywindow_globals.m_bRightClick == false ) {
1223 if ( !m_mnuDrop ) { // first time, load it up
1224 auto menu = m_mnuDrop = ui::Menu(ui::New);
1226 EntityClassMenuInserter inserter( menu );
1227 GlobalEntityClassManager().forEach( inserter );
1230 gtk_menu_popup( m_mnuDrop, 0, 0, 0, 0, 1, GDK_CURRENT_TIME );
1233 FreezePointer g_xywnd_freezePointer;
1235 unsigned int Move_buttons(){
1239 void XYWnd_moveDelta( int x, int y, unsigned int state, void* data ){
1240 reinterpret_cast<XYWnd*>( data )->EntityCreate_MouseMove( x, y );
1241 reinterpret_cast<XYWnd*>( data )->Scroll( -x, y );
1244 gboolean XYWnd_Move_focusOut( ui::Widget widget, GdkEventFocus* event, XYWnd* xywnd ){
1249 void XYWnd::Move_Begin(){
1250 if ( m_move_started ) {
1253 m_move_started = true;
1254 /* NetRadiantCustom did this instead:
1255 g_xywnd_freezePointer.freeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), m_gl_widget, XYWnd_moveDelta, this ); */
1256 g_xywnd_freezePointer.freeze_pointer( m_gl_widget, XYWnd_moveDelta, this );
1257 m_move_focusOut = m_gl_widget.connect( "focus_out_event", G_CALLBACK( XYWnd_Move_focusOut ), this );
1260 void XYWnd::Move_End(){
1261 m_move_started = false;
1262 /* NetRadiant did this instead:
1263 g_xywnd_freezePointer.unfreeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), false ); */
1264 g_xywnd_freezePointer.unfreeze_pointer( m_gl_widget, false );
1265 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_move_focusOut );
1268 unsigned int Zoom_buttons(){
1269 return RAD_RBUTTON | RAD_ALT;
1274 void XYWnd_zoomDelta( int x, int y, unsigned int state, void* data ){
1277 while ( abs( g_dragZoom ) > 8 )
1279 if ( g_dragZoom > 0 ) {
1280 reinterpret_cast<XYWnd*>( data )->ZoomOut();
1285 reinterpret_cast<XYWnd*>( data )->ZoomIn();
1292 gboolean XYWnd_Zoom_focusOut( ui::Widget widget, GdkEventFocus* event, XYWnd* xywnd ){
1297 void XYWnd::Zoom_Begin(){
1298 if ( m_zoom_started ) {
1301 m_zoom_started = true;
1303 /* NetRadiantCustom did this instead:
1304 g_xywnd_freezePointer.freeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), m_gl_widget, XYWnd_zoomDelta, this ); */
1305 g_xywnd_freezePointer.freeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), XYWnd_zoomDelta, this );
1306 m_zoom_focusOut = m_gl_widget.connect( "focus_out_event", G_CALLBACK( XYWnd_Zoom_focusOut ), this );
1309 void XYWnd::Zoom_End(){
1310 m_zoom_started = false;
1311 g_xywnd_freezePointer.unfreeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), false );
1312 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_zoom_focusOut );
1315 // makes sure the selected brush or camera is in view
1316 void XYWnd::PositionView( const Vector3& position ){
1317 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1318 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1320 m_vOrigin[nDim1] = position[nDim1];
1321 m_vOrigin[nDim2] = position[nDim2];
1325 XYWnd_Update( *this );
1328 void XYWnd::SetViewType( VIEWTYPE viewType ){
1329 m_viewType = viewType;
1333 gtk_window_set_title( m_parent, ViewType_getTitle( m_viewType ) );
1338 inline WindowVector WindowVector_forInteger( int x, int y ){
1339 return WindowVector( static_cast<float>( x ), static_cast<float>( y ) );
1342 void XYWnd::mouseDown( const WindowVector& position, ButtonIdentifier button, ModifierFlags modifiers ){
1343 XY_MouseDown( static_cast<int>( position.x() ), static_cast<int>( position.y() ), buttons_for_button_and_modifiers( button, modifiers ) );
1345 void XYWnd::XY_MouseDown( int x, int y, unsigned int buttons ){
1346 if ( buttons == Move_buttons() ) {
1348 EntityCreate_MouseDown( x, y );
1350 else if ( buttons == Zoom_buttons() ) {
1353 else if ( ClipMode() && ( buttons == Clipper_buttons() || buttons == Clipper_quick_buttons() ) ) {
1354 Clipper_OnLButtonDown( x, y );
1356 else if ( !ClipMode() && buttons == Clipper_quick_buttons() ) {
1358 g_quick_clipper = true;
1359 Clipper_OnLButtonDown( x, y );
1361 else if ( buttons == NewBrushDrag_buttons() && GlobalSelectionSystem().countSelected() == 0 ) {
1362 NewBrushDrag_Begin( x, y );
1364 // control mbutton = move camera
1365 else if ( buttons == MoveCamera_buttons() ) {
1366 XYWnd_PositionCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1368 // mbutton = angle camera
1369 else if ( buttons == OrientCamera_buttons() ) {
1370 XYWnd_OrientCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1372 else if ( buttons == SetCustomPivotOrigin_buttons() ) {
1373 SetCustomPivotOrigin( x, y );
1377 m_window_observer->onMouseDown( WindowVector_forInteger( x, y ), button_for_flags( buttons ), modifiers_for_flags( buttons ) );
1381 void XYWnd::XY_MouseUp( int x, int y, unsigned int buttons ){
1382 if ( m_move_started ) {
1384 EntityCreate_MouseUp( x, y );
1386 else if ( m_zoom_started ) {
1389 else if ( ClipMode() && ( buttons == Clipper_buttons() || buttons == Clipper_quick_buttons() ) ) {
1390 Clipper_OnLButtonUp( x, y );
1392 else if ( m_bNewBrushDrag ) {
1393 m_bNewBrushDrag = false;
1394 NewBrushDrag_End( x, y );
1395 if ( m_NewBrushDrag == 0 ) {
1396 //L button w/o created brush = tunnel selection
1397 m_window_observer->onMouseUp( WindowVector_forInteger( x, y ), button_for_flags( buttons ), modifiers_for_flags( buttons ) );
1402 m_window_observer->onMouseUp( WindowVector_forInteger( x, y ), button_for_flags( buttons ), modifiers_for_flags( buttons ) );
1406 void XYWnd::XY_MouseMoved( int x, int y, unsigned int buttons ){
1407 // rbutton = drag xy origin
1408 if ( m_move_started ) {
1411 else if ( m_zoom_started ) {
1414 else if ( ClipMode() && g_pMovingClip != 0 ) {
1415 Clipper_OnMouseMoved( x, y );
1417 // lbutton without selection = drag new brush
1418 else if ( m_bNewBrushDrag ) {
1419 NewBrushDrag( x, y );
1422 // control mbutton = move camera
1423 else if ( getButtonState() == MoveCamera_buttons() ) {
1424 XYWnd_PositionCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1427 // mbutton = angle camera
1428 else if ( getButtonState() == OrientCamera_buttons() ) {
1429 XYWnd_OrientCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1432 else if ( buttons == SetCustomPivotOrigin_buttons() ) {
1433 SetCustomPivotOrigin( x, y );
1438 m_window_observer->onMouseMotion( WindowVector_forInteger( x, y ), modifiers_for_flags( buttons ) );
1440 m_mousePosition[0] = m_mousePosition[1] = m_mousePosition[2] = 0.0;
1441 XY_ToPoint( x, y, m_mousePosition );
1442 XY_SnapToGrid( m_mousePosition );
1444 StringOutputStream status( 64 );
1445 status << "x:: " << FloatFormat( m_mousePosition[0], 6, 1 )
1446 << " y:: " << FloatFormat( m_mousePosition[1], 6, 1 )
1447 << " z:: " << FloatFormat( m_mousePosition[2], 6, 1 );
1448 g_pParentWnd->SetStatusText( g_pParentWnd->m_position_status, status.c_str() );
1450 if ( g_xywindow_globals_private.g_bCrossHairs ) {
1451 XYWnd_Update( *this );
1454 Clipper_Crosshair_OnMouseMoved( x, y );
1458 void XYWnd::EntityCreate_MouseDown( int x, int y ){
1459 m_entityCreate = true;
1460 m_entityCreate_x = x;
1461 m_entityCreate_y = y;
1464 void XYWnd::EntityCreate_MouseMove( int x, int y ){
1465 if ( m_entityCreate && ( m_entityCreate_x != x || m_entityCreate_y != y ) ) {
1466 m_entityCreate = false;
1470 void XYWnd::EntityCreate_MouseUp( int x, int y ){
1471 if ( m_entityCreate ) {
1472 m_entityCreate = false;
1477 inline float screen_normalised( int pos, unsigned int size ){
1478 return ( ( 2.0f * pos ) / size ) - 1.0f;
1481 inline float normalised_to_world( float normalised, float world_origin, float normalised2world_scale ){
1482 return world_origin + normalised * normalised2world_scale;
1486 // TTimo: watch it, this doesn't init one of the 3 coords
1487 void XYWnd::XY_ToPoint( int x, int y, Vector3& point ){
1488 float normalised2world_scale_x = m_nWidth / 2 / m_fScale;
1489 float normalised2world_scale_y = m_nHeight / 2 / m_fScale;
1490 if ( m_viewType == XY ) {
1491 point[0] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[0], normalised2world_scale_x );
1492 point[1] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[1], normalised2world_scale_y );
1494 else if ( m_viewType == YZ ) {
1495 point[1] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[1], normalised2world_scale_x );
1496 point[2] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[2], normalised2world_scale_y );
1500 point[0] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[0], normalised2world_scale_x );
1501 point[2] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[2], normalised2world_scale_y );
1505 void XYWnd::XY_SnapToGrid( Vector3& point ){
1506 if ( m_viewType == XY ) {
1507 point[0] = float_snapped( point[0], GetSnapGridSize() );
1508 point[1] = float_snapped( point[1], GetSnapGridSize() );
1510 else if ( m_viewType == YZ ) {
1511 point[1] = float_snapped( point[1], GetSnapGridSize() );
1512 point[2] = float_snapped( point[2], GetSnapGridSize() );
1516 point[0] = float_snapped( point[0], GetSnapGridSize() );
1517 point[2] = float_snapped( point[2], GetSnapGridSize() );
1521 void XYWnd::XY_LoadBackgroundImage( const char *name ){
1522 const char* relative = path_make_relative( name, GlobalFileSystem().findRoot( name ) );
1523 if ( relative == name ) {
1524 globalOutputStream() << "WARNING: could not extract the relative path, using full path instead\n";
1527 char fileNameWithoutExt[512];
1528 strncpy( fileNameWithoutExt, relative, sizeof( fileNameWithoutExt ) - 1 );
1529 fileNameWithoutExt[512 - 1] = '\0';
1530 fileNameWithoutExt[strlen( fileNameWithoutExt ) - 4] = '\0';
1532 Image *image = QERApp_LoadImage( 0, fileNameWithoutExt );
1534 globalOutputStream() << "Could not load texture " << fileNameWithoutExt << "\n";
1537 g_pParentWnd->ActiveXY()->m_tex = (qtexture_t*)malloc( sizeof( qtexture_t ) );
1538 LoadTextureRGBA( g_pParentWnd->ActiveXY()->XYWnd::m_tex, image->getRGBAPixels(), image->getWidth(), image->getHeight() );
1539 globalOutputStream() << "Loaded background texture " << relative << "\n";
1540 g_pParentWnd->ActiveXY()->m_backgroundActivated = true;
1543 switch ( g_pParentWnd->ActiveXY()->m_viewType )
1560 Select_GetBounds( min, max );
1561 g_pParentWnd->ActiveXY()->m_xmin = min[m_ix];
1562 g_pParentWnd->ActiveXY()->m_ymin = min[m_iy];
1563 g_pParentWnd->ActiveXY()->m_xmax = max[m_ix];
1564 g_pParentWnd->ActiveXY()->m_ymax = max[m_iy];
1567 void XYWnd::XY_DisableBackground( void ){
1568 g_pParentWnd->ActiveXY()->m_backgroundActivated = false;
1569 if ( g_pParentWnd->ActiveXY()->m_tex ) {
1570 free( g_pParentWnd->ActiveXY()->m_tex );
1572 g_pParentWnd->ActiveXY()->m_tex = NULL;
1575 void WXY_BackgroundSelect( void ){
1576 bool brushesSelected = Scene_countSelectedBrushes( GlobalSceneGraph() ) != 0;
1578 ui::Window main_window = MainFrame_getWindow();
1580 if ( !brushesSelected ) {
1581 ui::alert( main_window, "You have to select some brushes to get the bounding box for.\n",
1582 "No selection", ui::alert_type::OK, ui::alert_icon::Error );
1586 const char *filename = main_window.file_dialog( TRUE, "Background Image", NULL, NULL );
1588 g_pParentWnd->ActiveXY()->XY_DisableBackground();
1591 g_pParentWnd->ActiveXY()->XY_LoadBackgroundImage( filename );
1594 // Draw the background image immediately (do not wait for user input).
1595 g_pParentWnd->ActiveXY()->Redraw();
1599 ============================================================================
1603 ============================================================================
1612 double two_to_the_power( int power ){
1613 return pow( 2.0f, power );
1616 void XYWnd::XY_DrawAxis( void ){
1617 if ( g_xywindow_globals_private.show_axis ) {
1618 const char g_AxisName[3] = { 'X', 'Y', 'Z' };
1619 const int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1620 const int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1621 const int w = ( m_nWidth / 2 / m_fScale );
1622 const int h = ( m_nHeight / 2 / m_fScale );
1624 Vector3 colourX = ( m_viewType == YZ ) ? g_xywindow_globals.AxisColorY : g_xywindow_globals.AxisColorX;
1625 Vector3 colourY = ( m_viewType == XY ) ? g_xywindow_globals.AxisColorY : g_xywindow_globals.AxisColorZ;
1627 float grayX = vector3_dot( colourX, Vector3( 0.2989, 0.5870, 0.1140 ) );
1628 float grayY = vector3_dot( colourY, Vector3( 0.2989, 0.5870, 0.1140 ) );
1629 colourX[0] = colourX[1] = colourX[2] = grayX;
1630 colourY[0] = colourY[1] = colourY[2] = grayY;
1633 // draw two lines with corresponding axis colors to highlight current view
1634 // horizontal line: nDim1 color
1636 glBegin( GL_LINES );
1637 glColor3fv( vector3_to_array( colourX ) );
1638 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1639 glVertex2f( m_vOrigin[nDim1] - w + 65 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1641 glVertex2f( 32 / m_fScale, 0 );
1642 glColor3fv( vector3_to_array( colourY ) );
1643 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1644 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 20 / m_fScale );
1646 glVertex2f( 0, 32 / m_fScale );
1649 // now print axis symbols
1650 glColor3fv( vector3_to_array( colourX ) );
1651 glRasterPos2f( m_vOrigin[nDim1] - w + 55 / m_fScale, m_vOrigin[nDim2] + h - 55 / m_fScale );
1652 GlobalOpenGL().drawChar( g_AxisName[nDim1] );
1653 glRasterPos2f( 28 / m_fScale, -10 / m_fScale );
1654 GlobalOpenGL().drawChar( g_AxisName[nDim1] );
1655 glColor3fv( vector3_to_array( colourY ) );
1656 glRasterPos2f( m_vOrigin[nDim1] - w + 25 / m_fScale, m_vOrigin[nDim2] + h - 30 / m_fScale );
1657 GlobalOpenGL().drawChar( g_AxisName[nDim2] );
1658 glRasterPos2f( -10 / m_fScale, 28 / m_fScale );
1659 GlobalOpenGL().drawChar( g_AxisName[nDim2] );
1663 void XYWnd::RenderActive( void ){
1664 if ( glwidget_make_current( m_gl_widget ) != FALSE ) {
1665 if ( Map_Valid( g_map ) && ScreenUpdates_Enabled() ) {
1666 GlobalOpenGL_debugAssertNoErrors();
1667 glDrawBuffer( GL_FRONT );
1669 if ( g_xywindow_globals_private.show_outline ) {
1670 glMatrixMode( GL_PROJECTION );
1672 glOrtho( 0, m_nWidth, 0, m_nHeight, 0, 1 );
1674 glMatrixMode( GL_MODELVIEW );
1677 if( !Active() ){ //sorta erase
1678 glColor3fv( vector3_to_array( g_xywindow_globals.color_gridmajor ) );
1680 // four view mode doesn't colorize
1681 else if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) {
1682 glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) );
1686 switch ( m_viewType )
1689 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorX ) );
1692 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorY ) );
1695 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorZ ) );
1699 glBegin( GL_LINE_LOOP );
1700 glVertex2f( 0.5, 0.5 );
1701 glVertex2f( m_nWidth - 0.5, 1 );
1702 glVertex2f( m_nWidth - 0.5, m_nHeight - 0.5 );
1703 glVertex2f( 0.5, m_nHeight - 0.5 );
1706 // we do this part (the old way) only if show_axis is disabled
1707 if ( !g_xywindow_globals_private.show_axis ) {
1708 glMatrixMode( GL_PROJECTION );
1710 glOrtho( 0, m_nWidth, 0, m_nHeight, 0, 1 );
1712 glMatrixMode( GL_MODELVIEW );
1716 glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) );
1719 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridtext, 1.0f ) ) );
1722 glDisable( GL_BLEND );
1723 glRasterPos2f( 35, m_nHeight - 20 );
1725 GlobalOpenGL().drawString( ViewType_getTitle( m_viewType ) );
1729 glViewport( 0, 0, m_nWidth, m_nHeight );
1731 glMatrixMode( GL_PROJECTION );
1732 glLoadMatrixf( reinterpret_cast<const float*>( &m_projection ) );
1734 glMatrixMode( GL_MODELVIEW );
1736 glScalef( m_fScale, m_fScale, 1 );
1737 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1738 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1739 glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 );
1741 glDisable( GL_LINE_STIPPLE );
1742 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
1743 glDisableClientState( GL_NORMAL_ARRAY );
1744 glDisableClientState( GL_COLOR_ARRAY );
1745 glDisable( GL_TEXTURE_2D );
1746 glDisable( GL_LIGHTING );
1747 glDisable( GL_COLOR_MATERIAL );
1748 glDisable( GL_DEPTH_TEST );
1749 glDisable( GL_TEXTURE_1D );
1750 glDisable( GL_BLEND );
1752 XYWnd::XY_DrawAxis();
1755 glDrawBuffer( GL_BACK );
1756 GlobalOpenGL_debugAssertNoErrors();
1757 glwidget_make_current( m_gl_widget );
1762 void XYWnd::XY_DrawBackground( void ){
1763 glPushAttrib( GL_ALL_ATTRIB_BITS );
1765 glEnable( GL_TEXTURE_2D );
1766 glEnable( GL_BLEND );
1767 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
1768 glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1769 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
1770 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
1772 glPolygonMode( GL_FRONT, GL_FILL );
1774 glBindTexture( GL_TEXTURE_2D, m_tex->texture_number );
1775 glBegin( GL_QUADS );
1777 glColor4f( 1.0, 1.0, 1.0, m_alpha );
1778 glTexCoord2f( 0.0, 1.0 );
1779 glVertex2f( m_xmin, m_ymin );
1781 glTexCoord2f( 1.0, 1.0 );
1782 glVertex2f( m_xmax, m_ymin );
1784 glTexCoord2f( 1.0, 0.0 );
1785 glVertex2f( m_xmax, m_ymax );
1787 glTexCoord2f( 0.0, 0.0 );
1788 glVertex2f( m_xmin, m_ymax );
1791 glBindTexture( GL_TEXTURE_2D, 0 );
1796 void XYWnd::XY_DrawGrid( void ) {
1797 float x, y, xb, xe, yb, ye;
1800 float step, minor_step, stepx, stepy;
1801 step = minor_step = stepx = stepy = GetGridSize();
1803 int minor_power = Grid_getPower();
1806 while ( ( minor_step * m_fScale ) <= 4.0f ) { // make sure minor grid spacing is at least 4 pixels on the screen
1810 int power = minor_power;
1811 while ( ( power % 3 ) != 0 || ( step * m_fScale ) <= 32.0f ) { // make sure major grid spacing is at least 32 pixels on the screen
1813 step = float(two_to_the_power( power ) );
1815 mask = ( 1 << ( power - minor_power ) ) - 1;
1816 while ( ( stepx * m_fScale ) <= 32.0f ) // text step x must be at least 32
1818 while ( ( stepy * m_fScale ) <= 32.0f ) // text step y must be at least 32
1821 a = ( ( GetSnapGridSize() > 0.0f ) ? 1.0f : 0.3f );
1823 glDisable( GL_TEXTURE_2D );
1824 glDisable( GL_TEXTURE_1D );
1825 glDisable( GL_DEPTH_TEST );
1826 glDisable( GL_BLEND );
1829 w = ( m_nWidth / 2 / m_fScale );
1830 h = ( m_nHeight / 2 / m_fScale );
1832 const int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1833 const 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 = step * floor( xb / step );
1841 xe = m_vOrigin[nDim1] + w;
1842 if ( xe > region_maxs[nDim1] ) {
1843 xe = region_maxs[nDim1];
1845 xe = step * ceil( xe / step );
1847 yb = m_vOrigin[nDim2] - h;
1848 if ( yb < region_mins[nDim2] ) {
1849 yb = region_mins[nDim2];
1851 yb = step * floor( yb / step );
1853 ye = m_vOrigin[nDim2] + h;
1854 if ( ye > region_maxs[nDim2] ) {
1855 ye = region_maxs[nDim2];
1857 ye = step * ceil( ye / step );
1859 #define COLORS_DIFFER( a,b ) \
1860 ( ( a )[0] != ( b )[0] || \
1861 ( a )[1] != ( b )[1] || \
1862 ( a )[2] != ( b )[2] )
1865 // draw minor blocks
1866 if ( g_xywindow_globals_private.d_showgrid || a < 1.0f ) {
1868 glEnable( GL_BLEND );
1871 if ( COLORS_DIFFER( g_xywindow_globals.color_gridminor, g_xywindow_globals.color_gridback ) ) {
1872 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridminor, a ) ) );
1874 glBegin( GL_LINES );
1876 for ( x = xb ; x < xe ; x += minor_step, ++i ) {
1877 if ( ( i & mask ) != 0 ) {
1878 glVertex2f( x, yb );
1879 glVertex2f( x, ye );
1883 for ( y = yb ; y < ye ; y += minor_step, ++i ) {
1884 if ( ( i & mask ) != 0 ) {
1885 glVertex2f( xb, y );
1886 glVertex2f( xe, y );
1892 // draw major blocks
1893 if ( COLORS_DIFFER( g_xywindow_globals.color_gridmajor, g_xywindow_globals.color_gridminor ) ) {
1894 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridmajor, a ) ) );
1896 glBegin( GL_LINES );
1897 for ( x = xb ; x <= xe ; x += step ) {
1898 glVertex2f( x, yb );
1899 glVertex2f( x, ye );
1901 for ( y = yb ; y <= ye ; y += step ) {
1902 glVertex2f( xb, y );
1903 glVertex2f( xe, y );
1909 glDisable( GL_BLEND );
1913 // draw coordinate text if needed
1914 if ( g_xywindow_globals_private.show_coordinates ) {
1915 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridtext, 1.0f ) ) );
1916 float offx = m_vOrigin[nDim2] + h - ( 4 + GlobalOpenGL().m_font->getPixelAscent() ) / m_fScale;
1917 float offy = m_vOrigin[nDim1] - w + 4 / m_fScale;
1918 for ( x = xb - fmod( xb, stepx ); x <= xe ; x += stepx ) {
1919 glRasterPos2f( x, offx );
1920 sprintf( text, "%g", x );
1921 GlobalOpenGL().drawString( text );
1923 for ( y = yb - fmod( yb, stepy ); y <= ye ; y += stepy ) {
1924 glRasterPos2f( offy, y );
1925 sprintf( text, "%g", y );
1926 GlobalOpenGL().drawString( text );
1930 // we do this part (the old way) only if show_axis is disabled
1931 if ( !g_xywindow_globals_private.show_axis ) {
1933 glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) );
1936 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridtext, 1.0f ) ) );
1939 glRasterPos2f( m_vOrigin[nDim1] - w + 35 / m_fScale, m_vOrigin[nDim2] + h - 20 / m_fScale );
1941 GlobalOpenGL().drawString( ViewType_getTitle( m_viewType ) );
1944 XYWnd::XY_DrawAxis();
1946 // show current work zone?
1947 // the work zone is used to place dropped points and brushes
1948 if ( g_xywindow_globals_private.d_show_work ) {
1949 glColor4f( 1.0f, 0.0f, 0.0f, 1.0f );
1950 glBegin( GL_LINES );
1951 glVertex2f( xb, Select_getWorkZone().d_work_min[nDim2] );
1952 glVertex2f( xe, Select_getWorkZone().d_work_min[nDim2] );
1953 glVertex2f( xb, Select_getWorkZone().d_work_max[nDim2] );
1954 glVertex2f( xe, Select_getWorkZone().d_work_max[nDim2] );
1955 glVertex2f( Select_getWorkZone().d_work_min[nDim1], yb );
1956 glVertex2f( Select_getWorkZone().d_work_min[nDim1], ye );
1957 glVertex2f( Select_getWorkZone().d_work_max[nDim1], yb );
1958 glVertex2f( Select_getWorkZone().d_work_max[nDim1], ye );
1968 void XYWnd::XY_DrawBlockGrid(){
1969 if ( Map_FindWorldspawn( g_map ) == 0 ) {
1972 const char *value = Node_getEntity( *Map_GetWorldspawn( g_map ) )->getKeyValue( "_blocksize" );
1973 if ( strlen( value ) ) {
1974 sscanf( value, "%i", &g_xywindow_globals_private.blockSize );
1977 if ( !g_xywindow_globals_private.blockSize || g_xywindow_globals_private.blockSize > 65536 || g_xywindow_globals_private.blockSize < 1024 ) {
1978 // don't use custom blocksize if it is less than the default, or greater than the maximum world coordinate
1979 g_xywindow_globals_private.blockSize = 1024;
1982 float x, y, xb, xe, yb, ye;
1986 glDisable( GL_TEXTURE_2D );
1987 glDisable( GL_TEXTURE_1D );
1988 glDisable( GL_DEPTH_TEST );
1989 glDisable( GL_BLEND );
1991 w = ( m_nWidth / 2 / m_fScale );
1992 h = ( m_nHeight / 2 / m_fScale );
1994 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1995 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1997 xb = m_vOrigin[nDim1] - w;
1998 if ( xb < region_mins[nDim1] ) {
1999 xb = region_mins[nDim1];
2001 xb = static_cast<float>( g_xywindow_globals_private.blockSize * floor( xb / g_xywindow_globals_private.blockSize ) );
2003 xe = m_vOrigin[nDim1] + w;
2004 if ( xe > region_maxs[nDim1] ) {
2005 xe = region_maxs[nDim1];
2007 xe = static_cast<float>( g_xywindow_globals_private.blockSize * ceil( xe / g_xywindow_globals_private.blockSize ) );
2009 yb = m_vOrigin[nDim2] - h;
2010 if ( yb < region_mins[nDim2] ) {
2011 yb = region_mins[nDim2];
2013 yb = static_cast<float>( g_xywindow_globals_private.blockSize * floor( yb / g_xywindow_globals_private.blockSize ) );
2015 ye = m_vOrigin[nDim2] + h;
2016 if ( ye > region_maxs[nDim2] ) {
2017 ye = region_maxs[nDim2];
2019 ye = static_cast<float>( g_xywindow_globals_private.blockSize * ceil( ye / g_xywindow_globals_private.blockSize ) );
2021 // draw major blocks
2023 glColor3fv( vector3_to_array( g_xywindow_globals.color_gridblock ) );
2026 glBegin( GL_LINES );
2028 for ( x = xb ; x <= xe ; x += g_xywindow_globals_private.blockSize )
2030 glVertex2f( x, yb );
2031 glVertex2f( x, ye );
2034 if ( m_viewType == XY ) {
2035 for ( y = yb ; y <= ye ; y += g_xywindow_globals_private.blockSize )
2037 glVertex2f( xb, y );
2038 glVertex2f( xe, y );
2045 // draw coordinate text if needed
2047 if ( m_viewType == XY && m_fScale > .1 ) {
2048 for ( x = xb ; x < xe ; x += g_xywindow_globals_private.blockSize )
2049 for ( y = yb ; y < ye ; y += g_xywindow_globals_private.blockSize )
2051 glRasterPos2f( x + ( g_xywindow_globals_private.blockSize / 2 ), y + ( g_xywindow_globals_private.blockSize / 2 ) );
2052 sprintf( text, "%i,%i",(int)floor( x / g_xywindow_globals_private.blockSize ), (int)floor( y / g_xywindow_globals_private.blockSize ) );
2053 GlobalOpenGL().drawString( text );
2057 glColor4f( 0, 0, 0, 0 );
2060 void XYWnd::DrawCameraIcon( const Vector3& origin, const Vector3& angles ){
2061 float x, y, fov, box;
2064 fov = 48 / m_fScale;
2065 box = 16 / m_fScale;
2067 if ( m_viewType == XY ) {
2070 a = degrees_to_radians( angles[CAMERA_YAW] );
2072 else if ( m_viewType == YZ ) {
2075 a = degrees_to_radians( angles[CAMERA_PITCH] );
2081 a = degrees_to_radians( angles[CAMERA_PITCH] );
2084 glColor3f( 0.0, 0.0, 1.0 );
2085 glBegin( GL_LINE_STRIP );
2086 glVertex3f( x - box,y,0 );
2087 glVertex3f( x,y + ( box / 2 ),0 );
2088 glVertex3f( x + box,y,0 );
2089 glVertex3f( x,y - ( box / 2 ),0 );
2090 glVertex3f( x - box,y,0 );
2091 glVertex3f( x + box,y,0 );
2094 glBegin( GL_LINE_STRIP );
2095 glVertex3f( x + static_cast<float>( fov * cos( a + c_pi / 4 ) ), y + static_cast<float>( fov * sin( a + c_pi / 4 ) ), 0 );
2096 glVertex3f( x, y, 0 );
2097 glVertex3f( x + static_cast<float>( fov * cos( a - c_pi / 4 ) ), y + static_cast<float>( fov * sin( a - c_pi / 4 ) ), 0 );
2103 float Betwixt( float f1, float f2 ){
2105 return f2 + ( ( f1 - f2 ) / 2 );
2108 return f1 + ( ( f2 - f1 ) / 2 );
2113 // can be greatly simplified but per usual i am in a hurry
2114 // which is not an excuse, just a fact
2115 void XYWnd::PaintSizeInfo( int nDim1, int nDim2, Vector3& vMinBounds, Vector3& vMaxBounds ){
2116 if ( vector3_equal( vMinBounds, vMaxBounds ) ) {
2119 const char* g_pDimStrings[] = {"x:", "y:", "z:"};
2120 typedef const char* OrgStrings[2];
2121 const OrgStrings g_pOrgStrings[] = { { "x:", "y:", }, { "x:", "z:", }, { "y:", "z:", } };
2123 Vector3 vSize( vector3_subtracted( vMaxBounds, vMinBounds ) );
2125 glColor3f( g_xywindow_globals.color_selbrushes[0] * .65f,
2126 g_xywindow_globals.color_selbrushes[1] * .65f,
2127 g_xywindow_globals.color_selbrushes[2] * .65f );
2129 StringOutputStream dimensions( 16 );
2131 if ( m_viewType == XY ) {
2132 glBegin( GL_LINES );
2134 glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f );
2135 glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
2137 glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
2138 glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
2140 glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f );
2141 glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
2144 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2], 0.0f );
2145 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f );
2147 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f );
2148 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f );
2150 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2], 0.0f );
2151 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f );
2155 glRasterPos3f( Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), vMinBounds[nDim2] - 20.0f / m_fScale, 0.0f );
2156 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
2157 GlobalOpenGL().drawString( dimensions.c_str() );
2160 glRasterPos3f( vMaxBounds[nDim1] + 16.0f / m_fScale, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ), 0.0f );
2161 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
2162 GlobalOpenGL().drawString( dimensions.c_str() );
2165 glRasterPos3f( vMinBounds[nDim1] + 4, vMaxBounds[nDim2] + 8 / m_fScale, 0.0f );
2166 dimensions << "(" << g_pOrgStrings[0][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[0][1] << vMaxBounds[nDim2] << ")";
2167 GlobalOpenGL().drawString( dimensions.c_str() );
2169 else if ( m_viewType == XZ ) {
2170 glBegin( GL_LINES );
2172 glVertex3f( vMinBounds[nDim1], 0, vMinBounds[nDim2] - 6.0f / m_fScale );
2173 glVertex3f( vMinBounds[nDim1], 0, vMinBounds[nDim2] - 10.0f / m_fScale );
2175 glVertex3f( vMinBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale );
2176 glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale );
2178 glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 6.0f / m_fScale );
2179 glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale );
2182 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, 0,vMinBounds[nDim2] );
2183 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMinBounds[nDim2] );
2185 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMinBounds[nDim2] );
2186 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMaxBounds[nDim2] );
2188 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, 0,vMaxBounds[nDim2] );
2189 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMaxBounds[nDim2] );
2193 glRasterPos3f( Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), 0, vMinBounds[nDim2] - 20.0f / m_fScale );
2194 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
2195 GlobalOpenGL().drawString( dimensions.c_str() );
2198 glRasterPos3f( vMaxBounds[nDim1] + 16.0f / m_fScale, 0, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ) );
2199 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
2200 GlobalOpenGL().drawString( dimensions.c_str() );
2203 glRasterPos3f( vMinBounds[nDim1] + 4, 0, vMaxBounds[nDim2] + 8 / m_fScale );
2204 dimensions << "(" << g_pOrgStrings[1][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[1][1] << vMaxBounds[nDim2] << ")";
2205 GlobalOpenGL().drawString( dimensions.c_str() );
2209 glBegin( GL_LINES );
2211 glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale );
2212 glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2214 glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2215 glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2217 glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale );
2218 glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2221 glVertex3f( 0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2] );
2222 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2] );
2224 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2] );
2225 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2] );
2227 glVertex3f( 0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2] );
2228 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2] );
2232 glRasterPos3f( 0, Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), vMinBounds[nDim2] - 20.0f / m_fScale );
2233 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
2234 GlobalOpenGL().drawString( dimensions.c_str() );
2237 glRasterPos3f( 0, vMaxBounds[nDim1] + 16.0f / m_fScale, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ) );
2238 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
2239 GlobalOpenGL().drawString( dimensions.c_str() );
2242 glRasterPos3f( 0, vMinBounds[nDim1] + 4.0f, vMaxBounds[nDim2] + 8 / m_fScale );
2243 dimensions << "(" << g_pOrgStrings[2][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[2][1] << vMaxBounds[nDim2] << ")";
2244 GlobalOpenGL().drawString( dimensions.c_str() );
2248 class XYRenderer : public Renderer
2256 unsigned int m_highlight;
2260 XYRenderer( RenderStateFlags globalstate, Shader* selected ) :
2261 m_globalstate( globalstate ),
2262 m_state_selected( selected ){
2263 ASSERT_NOTNULL( selected );
2264 m_state_stack.push_back( state_type() );
2267 void SetState( Shader* state, EStyle style ){
2268 ASSERT_NOTNULL( state );
2269 if ( style == eWireframeOnly ) {
2270 m_state_stack.back().m_state = state;
2273 EStyle getStyle() const {
2274 return eWireframeOnly;
2277 m_state_stack.push_back( m_state_stack.back() );
2280 ASSERT_MESSAGE( !m_state_stack.empty(), "popping empty stack" );
2281 m_state_stack.pop_back();
2283 void Highlight( EHighlightMode mode, bool bEnable = true ){
2285 ? m_state_stack.back().m_highlight |= mode
2286 : m_state_stack.back().m_highlight &= ~mode;
2288 void addRenderable( const OpenGLRenderable& renderable, const Matrix4& localToWorld ){
2289 if ( m_state_stack.back().m_highlight & ePrimitive ) {
2290 m_state_selected->addRenderable( renderable, localToWorld );
2294 m_state_stack.back().m_state->addRenderable( renderable, localToWorld );
2298 void render( const Matrix4& modelview, const Matrix4& projection ){
2299 GlobalShaderCache().render( m_globalstate, modelview, projection );
2302 std::vector<state_type> m_state_stack;
2303 RenderStateFlags m_globalstate;
2304 Shader* m_state_selected;
2307 void XYWnd::updateProjection( bool reconstruct ){
2308 m_projection[0] = 1.0f / static_cast<float>( m_nWidth / 2 );
2309 m_projection[5] = 1.0f / static_cast<float>( m_nHeight / 2 );
2310 m_projection[10] = 1.0f / ( g_MaxWorldCoord * m_fScale );
2312 m_projection[12] = 0.0f;
2313 m_projection[13] = 0.0f;
2314 m_projection[14] = -1.0f;
2326 m_projection[11] = 0.0f;
2328 m_projection[15] = 1.0f;
2331 m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight );
2335 // note: modelview matrix must have a uniform scale, otherwise strange things happen when rendering the rotation manipulator.
2336 void XYWnd::updateModelview( bool reconstruct ){
2337 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
2338 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
2341 m_modelview[12] = -m_vOrigin[nDim1] * m_fScale;
2342 m_modelview[13] = -m_vOrigin[nDim2] * m_fScale;
2343 m_modelview[14] = g_MaxWorldCoord * m_fScale;
2346 switch ( m_viewType )
2349 m_modelview[0] = m_fScale;
2354 m_modelview[5] = m_fScale;
2359 m_modelview[10] = -m_fScale;
2362 m_modelview[0] = m_fScale;
2368 m_modelview[6] = m_fScale;
2371 m_modelview[9] = m_fScale;
2372 m_modelview[10] = 0;
2377 m_modelview[2] = -m_fScale;
2379 m_modelview[4] = m_fScale;
2384 m_modelview[9] = m_fScale;
2385 m_modelview[10] = 0;
2389 m_modelview[3] = m_modelview[7] = m_modelview[11] = 0;
2390 m_modelview[15] = 1;
2393 m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight );
2403 //#define DBG_SCENEDUMP
2405 void XYWnd::XY_Draw(){
2409 glViewport( 0, 0, m_nWidth, m_nHeight );
2410 glClearColor( g_xywindow_globals.color_gridback[0],
2411 g_xywindow_globals.color_gridback[1],
2412 g_xywindow_globals.color_gridback[2],0 );
2414 glClear( GL_COLOR_BUFFER_BIT );
2420 glMatrixMode( GL_PROJECTION );
2421 glLoadMatrixf( reinterpret_cast<const float*>( &m_projection ) );
2423 glMatrixMode( GL_MODELVIEW );
2425 glScalef( m_fScale, m_fScale, 1 );
2426 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
2427 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
2428 glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 );
2430 glDisable( GL_LINE_STIPPLE );
2432 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2433 glDisableClientState( GL_NORMAL_ARRAY );
2434 glDisableClientState( GL_COLOR_ARRAY );
2435 glDisable( GL_TEXTURE_2D );
2436 glDisable( GL_LIGHTING );
2437 glDisable( GL_COLOR_MATERIAL );
2438 glDisable( GL_DEPTH_TEST );
2440 if ( m_backgroundActivated ) {
2441 XY_DrawBackground();
2445 if ( g_xywindow_globals_private.show_blocks ) {
2449 glLoadMatrixf( reinterpret_cast<const float*>( &m_modelview ) );
2451 unsigned int globalstate = RENDER_COLOURARRAY | RENDER_COLOURWRITE | RENDER_POLYGONSMOOTH | RENDER_LINESMOOTH;
2452 if ( !g_xywindow_globals.m_bNoStipple ) {
2453 globalstate |= RENDER_LINESTIPPLE;
2457 XYRenderer renderer( globalstate, m_state_selected );
2459 Scene_Render( renderer, m_view );
2461 GlobalOpenGL_debugAssertNoErrors();
2462 renderer.render( m_modelview, m_projection );
2463 GlobalOpenGL_debugAssertNoErrors();
2466 glDepthMask( GL_FALSE );
2468 GlobalOpenGL_debugAssertNoErrors();
2470 glLoadMatrixf( reinterpret_cast<const float*>( &m_modelview ) );
2472 GlobalOpenGL_debugAssertNoErrors();
2473 glDisable( GL_LINE_STIPPLE );
2474 GlobalOpenGL_debugAssertNoErrors();
2476 GlobalOpenGL_debugAssertNoErrors();
2477 if ( GlobalOpenGL().GL_1_3() ) {
2478 glActiveTexture( GL_TEXTURE0 );
2479 glClientActiveTexture( GL_TEXTURE0 );
2481 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2482 GlobalOpenGL_debugAssertNoErrors();
2483 glDisableClientState( GL_NORMAL_ARRAY );
2484 GlobalOpenGL_debugAssertNoErrors();
2485 glDisableClientState( GL_COLOR_ARRAY );
2486 GlobalOpenGL_debugAssertNoErrors();
2487 glDisable( GL_TEXTURE_2D );
2488 GlobalOpenGL_debugAssertNoErrors();
2489 glDisable( GL_LIGHTING );
2490 GlobalOpenGL_debugAssertNoErrors();
2491 glDisable( GL_COLOR_MATERIAL );
2492 GlobalOpenGL_debugAssertNoErrors();
2494 GlobalOpenGL_debugAssertNoErrors();
2498 if ( g_xywindow_globals_private.m_bSizePaint && GlobalSelectionSystem().countSelected() != 0 ) {
2500 Select_GetBounds( min, max );
2501 PaintSizeInfo( nDim1, nDim2, min, max );
2504 if ( g_xywindow_globals_private.g_bCrossHairs ) {
2505 glColor4f( 0.2f, 0.9f, 0.2f, 0.8f );
2506 glBegin( GL_LINES );
2507 if ( m_viewType == XY ) {
2508 glVertex2f( 2.0f * g_MinWorldCoord, m_mousePosition[1] );
2509 glVertex2f( 2.0f * g_MaxWorldCoord, m_mousePosition[1] );
2510 glVertex2f( m_mousePosition[0], 2.0f * g_MinWorldCoord );
2511 glVertex2f( m_mousePosition[0], 2.0f * g_MaxWorldCoord );
2513 else if ( m_viewType == YZ ) {
2514 glVertex3f( m_mousePosition[0], 2.0f * g_MinWorldCoord, m_mousePosition[2] );
2515 glVertex3f( m_mousePosition[0], 2.0f * g_MaxWorldCoord, m_mousePosition[2] );
2516 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MinWorldCoord );
2517 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MaxWorldCoord );
2521 glVertex3f( 2.0f * g_MinWorldCoord, m_mousePosition[1], m_mousePosition[2] );
2522 glVertex3f( 2.0f * g_MaxWorldCoord, m_mousePosition[1], m_mousePosition[2] );
2523 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MinWorldCoord );
2524 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MaxWorldCoord );
2530 GlobalClipPoints_Draw( m_fScale );
2533 GlobalOpenGL_debugAssertNoErrors();
2537 glScalef( m_fScale, m_fScale, 1 );
2538 glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 );
2540 DrawCameraIcon( Camera_getOrigin( *g_pParentWnd->GetCamWnd() ), Camera_getAngles( *g_pParentWnd->GetCamWnd() ) );
2542 Feedback_draw2D( m_viewType );
2544 if ( g_xywindow_globals_private.show_outline ) {
2546 glMatrixMode( GL_PROJECTION );
2548 glOrtho( 0, m_nWidth, 0, m_nHeight, 0, 1 );
2550 glMatrixMode( GL_MODELVIEW );
2553 // four view mode doesn't colorize
2554 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) {
2555 glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) );
2559 switch ( m_viewType )
2562 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorX ) );
2565 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorY ) );
2568 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorZ ) );
2572 glBegin( GL_LINE_LOOP );
2573 glVertex2f( 0.5, 0.5 );
2574 glVertex2f( m_nWidth - 0.5, 1 );
2575 glVertex2f( m_nWidth - 0.5, m_nHeight - 0.5 );
2576 glVertex2f( 0.5, m_nHeight - 0.5 );
2581 GlobalOpenGL_debugAssertNoErrors();
2586 void XYWnd_MouseToPoint( XYWnd* xywnd, int x, int y, Vector3& point ){
2587 xywnd->XY_ToPoint( x, y, point );
2588 xywnd->XY_SnapToGrid( point );
2590 int nDim = ( xywnd->GetViewType() == XY ) ? 2 : ( xywnd->GetViewType() == YZ ) ? 0 : 1;
2591 float fWorkMid = float_mid( Select_getWorkZone().d_work_min[nDim], Select_getWorkZone().d_work_max[nDim] );
2592 point[nDim] = float_snapped( fWorkMid, GetGridSize() );
2595 void XYWnd::OnEntityCreate( const char* item ){
2596 StringOutputStream command;
2597 command << "entityCreate -class " << item;
2598 UndoableCommand undo( command.c_str() );
2600 XYWnd_MouseToPoint( this, m_entityCreate_x, m_entityCreate_y, point );
2601 Entity_createFromSelection( item, point );
2606 void GetFocusPosition( Vector3& position ){
2607 if ( GlobalSelectionSystem().countSelected() != 0 ) {
2608 Select_GetMid( position );
2612 position = Camera_getOrigin( *g_pParentWnd->GetCamWnd() );
2616 void XYWnd_Focus( XYWnd* xywnd ){
2618 GetFocusPosition( position );
2619 xywnd->PositionView( position );
2622 void XY_Split_Focus(){
2624 GetFocusPosition( position );
2625 if ( g_pParentWnd->GetXYWnd() ) {
2626 g_pParentWnd->GetXYWnd()->PositionView( position );
2628 if ( g_pParentWnd->GetXZWnd() ) {
2629 g_pParentWnd->GetXZWnd()->PositionView( position );
2631 if ( g_pParentWnd->GetYZWnd() ) {
2632 g_pParentWnd->GetYZWnd()->PositionView( position );
2637 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) {
2638 // cannot do this in a split window
2639 // do something else that the user may want here
2644 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2645 XYWnd_Focus( xywnd );
2649 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) {
2650 // cannot do this in a split window
2651 // do something else that the user may want here
2656 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2657 xywnd->SetViewType( XY );
2658 XYWnd_Focus( xywnd );
2662 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) {
2663 // cannot do this in a split window
2664 // do something else that the user may want here
2669 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2670 xywnd->SetViewType( XZ );
2671 XYWnd_Focus( xywnd );
2675 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) {
2676 // cannot do this in a split window
2677 // do something else that the user may want here
2682 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2683 xywnd->SetViewType( YZ );
2684 XYWnd_Focus( xywnd );
2688 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) {
2689 // cannot do this in a split window
2690 // do something else that the user may want here
2695 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2696 if ( xywnd->GetViewType() == XY ) {
2697 xywnd->SetViewType( XZ );
2699 else if ( xywnd->GetViewType() == XZ ) {
2700 xywnd->SetViewType( YZ );
2703 xywnd->SetViewType( XY );
2705 XYWnd_Focus( xywnd );
2709 if ( g_pParentWnd->GetXYWnd() ) {
2710 g_pParentWnd->GetXYWnd()->SetScale( 1 );
2712 if ( g_pParentWnd->GetXZWnd() ) {
2713 g_pParentWnd->GetXZWnd()->SetScale( 1 );
2715 if ( g_pParentWnd->GetYZWnd() ) {
2716 g_pParentWnd->GetYZWnd()->SetScale( 1 );
2721 g_pParentWnd->ActiveXY()->ZoomIn();
2724 // NOTE: the zoom out factor is 4/5, we could think about customizing it
2725 // we don't go below a zoom factor corresponding to 10% of the max world size
2726 // (this has to be computed against the window size)
2728 g_pParentWnd->ActiveXY()->ZoomOut();
2733 void ToggleShowCrosshair(){
2734 g_xywindow_globals_private.g_bCrossHairs ^= 1;
2735 XY_UpdateAllWindows();
2738 void ToggleShowSizeInfo(){
2739 g_xywindow_globals_private.m_bSizePaint = !g_xywindow_globals_private.m_bSizePaint;
2740 XY_UpdateAllWindows();
2743 void ToggleShowGrid(){
2744 g_xywindow_globals_private.d_showgrid = !g_xywindow_globals_private.d_showgrid;
2745 XY_UpdateAllWindows();
2748 ToggleShown g_xy_top_shown( true );
2750 void XY_Top_Shown_Construct( ui::Window parent ){
2751 g_xy_top_shown.connect( parent );
2754 ToggleShown g_yz_side_shown( false );
2756 void YZ_Side_Shown_Construct( ui::Window parent ){
2757 g_yz_side_shown.connect( parent );
2760 ToggleShown g_xz_front_shown( false );
2762 void XZ_Front_Shown_Construct( ui::Window parent ){
2763 g_xz_front_shown.connect( parent );
2767 class EntityClassMenu : public ModuleObserver
2769 std::size_t m_unrealised;
2771 EntityClassMenu() : m_unrealised( 1 ){
2774 if ( --m_unrealised == 0 ) {
2778 if ( ++m_unrealised == 1 ) {
2779 if ( XYWnd::m_mnuDrop ) {
2780 XYWnd::m_mnuDrop.destroy();
2781 XYWnd::m_mnuDrop = ui::Menu(ui::null);
2787 EntityClassMenu g_EntityClassMenu;
2792 void ShowNamesToggle(){
2793 GlobalEntityCreator().setShowNames( !GlobalEntityCreator().getShowNames() );
2794 XY_UpdateAllWindows();
2797 typedef FreeCaller<void(), ShowNamesToggle> ShowNamesToggleCaller;
2799 void ShowNamesExport( const Callback<void(bool)> & importer ){
2800 importer( GlobalEntityCreator().getShowNames() );
2803 typedef FreeCaller<void(const Callback<void(bool)> &), ShowNamesExport> ShowNamesExportCaller;
2806 void ShowAnglesToggle(){
2807 GlobalEntityCreator().setShowAngles( !GlobalEntityCreator().getShowAngles() );
2808 XY_UpdateAllWindows();
2811 typedef FreeCaller<void(), ShowAnglesToggle> ShowAnglesToggleCaller;
2813 void ShowAnglesExport( const Callback<void(bool)> & importer ){
2814 importer( GlobalEntityCreator().getShowAngles() );
2816 typedef FreeCaller<void(const Callback<void(bool)> &), ShowAnglesExport> ShowAnglesExportCaller;
2819 void ShowBlocksToggle(){
2820 g_xywindow_globals_private.show_blocks ^= 1;
2821 XY_UpdateAllWindows();
2824 typedef FreeCaller<void(), ShowBlocksToggle> ShowBlocksToggleCaller;
2826 void ShowBlocksExport( const Callback<void(bool)> & importer ){
2827 importer( g_xywindow_globals_private.show_blocks );
2830 typedef FreeCaller<void(const Callback<void(bool)> &), ShowBlocksExport> ShowBlocksExportCaller;
2833 void ShowCoordinatesToggle(){
2834 g_xywindow_globals_private.show_coordinates ^= 1;
2835 XY_UpdateAllWindows();
2838 typedef FreeCaller<void(), ShowCoordinatesToggle> ShowCoordinatesToggleCaller;
2840 void ShowCoordinatesExport( const Callback<void(bool)> & importer ){
2841 importer( g_xywindow_globals_private.show_coordinates );
2844 typedef FreeCaller<void(const Callback<void(bool)> &), ShowCoordinatesExport> ShowCoordinatesExportCaller;
2847 void ShowOutlineToggle(){
2848 g_xywindow_globals_private.show_outline ^= 1;
2849 XY_UpdateAllWindows();
2852 typedef FreeCaller<void(), ShowOutlineToggle> ShowOutlineToggleCaller;
2854 void ShowOutlineExport( const Callback<void(bool)> & importer ){
2855 importer( g_xywindow_globals_private.show_outline );
2858 typedef FreeCaller<void(const Callback<void(bool)> &), ShowOutlineExport> ShowOutlineExportCaller;
2861 void ShowAxesToggle(){
2862 g_xywindow_globals_private.show_axis ^= 1;
2863 XY_UpdateAllWindows();
2865 typedef FreeCaller<void(), ShowAxesToggle> ShowAxesToggleCaller;
2867 void ShowAxesExport( const Callback<void(bool)> & importer ){
2868 importer( g_xywindow_globals_private.show_axis );
2871 typedef FreeCaller<void(const Callback<void(bool)> &), ShowAxesExport> ShowAxesExportCaller;
2874 void ShowWorkzoneToggle(){
2875 g_xywindow_globals_private.d_show_work ^= 1;
2876 XY_UpdateAllWindows();
2878 typedef FreeCaller<void(), ShowWorkzoneToggle> ShowWorkzoneToggleCaller;
2880 void ShowWorkzoneExport( const Callback<void(bool)> & importer ){
2881 importer( g_xywindow_globals_private.d_show_work );
2884 typedef FreeCaller<void(const Callback<void(bool)> &), ShowWorkzoneExport> ShowWorkzoneExportCaller;
2887 BoolExportCaller g_texdef_movelock_caller( g_brush_texturelock_enabled );
2888 ToggleItem g_texdef_movelock_item( g_texdef_movelock_caller );
2890 void Texdef_ToggleMoveLock(){
2891 g_brush_texturelock_enabled = !g_brush_texturelock_enabled;
2892 g_texdef_movelock_item.update();
2897 void ShowSizeToggle(){
2898 g_xywindow_globals_private.m_bSizePaint = !g_xywindow_globals_private.m_bSizePaint;
2899 XY_UpdateAllWindows();
2901 typedef FreeCaller<void(), ShowSizeToggle> ShowSizeToggleCaller;
2902 void ShowSizeExport( const Callback<void(bool)> & importer ){
2903 importer( g_xywindow_globals_private.m_bSizePaint );
2905 typedef FreeCaller<void(const Callback<void(bool)> &), ShowSizeExport> ShowSizeExportCaller;
2908 void ShowCrosshairToggle(){
2909 g_xywindow_globals_private.g_bCrossHairs ^= 1;
2910 XY_UpdateAllWindows();
2912 typedef FreeCaller<void(), ShowCrosshairToggle> ShowCrosshairToggleCaller;
2913 void ShowCrosshairExport( const Callback<void(bool)> & importer ){
2914 importer( g_xywindow_globals_private.g_bCrossHairs );
2916 typedef FreeCaller<void(const Callback<void(bool)> &), ShowCrosshairExport> ShowCrosshairExportCaller;
2919 void ShowGridToggle(){
2920 g_xywindow_globals_private.d_showgrid = !g_xywindow_globals_private.d_showgrid;
2921 XY_UpdateAllWindows();
2923 typedef FreeCaller<void(), ShowGridToggle> ShowGridToggleCaller;
2924 void ShowGridTExport( const Callback<void(bool)> & importer ){
2925 importer( g_xywindow_globals_private.d_showgrid );
2927 typedef FreeCaller<void(const Callback<void(bool)> &), ShowSizeExport> ShowGridExportCaller;
2930 ShowNamesExportCaller g_show_names_caller;
2931 Callback<void(const Callback<void(bool)> &)> g_show_names_callback( g_show_names_caller );
2932 ToggleItem g_show_names( g_show_names_callback );
2934 ShowAnglesExportCaller g_show_angles_caller;
2935 Callback<void(const Callback<void(bool)> &)> g_show_angles_callback( g_show_angles_caller );
2936 ToggleItem g_show_angles( g_show_angles_callback );
2938 ShowBlocksExportCaller g_show_blocks_caller;
2939 Callback<void(const Callback<void(bool)> &)> g_show_blocks_callback( g_show_blocks_caller );
2940 ToggleItem g_show_blocks( g_show_blocks_callback );
2942 ShowCoordinatesExportCaller g_show_coordinates_caller;
2943 Callback<void(const Callback<void(bool)> &)> g_show_coordinates_callback( g_show_coordinates_caller );
2944 ToggleItem g_show_coordinates( g_show_coordinates_callback );
2946 ShowOutlineExportCaller g_show_outline_caller;
2947 Callback<void(const Callback<void(bool)> &)> g_show_outline_callback( g_show_outline_caller );
2948 ToggleItem g_show_outline( g_show_outline_callback );
2950 ShowAxesExportCaller g_show_axes_caller;
2951 Callback<void(const Callback<void(bool)> &)> g_show_axes_callback( g_show_axes_caller );
2952 ToggleItem g_show_axes( g_show_axes_callback );
2954 ShowWorkzoneExportCaller g_show_workzone_caller;
2955 Callback<void(const Callback<void(bool)> &)> g_show_workzone_callback( g_show_workzone_caller );
2956 ToggleItem g_show_workzone( g_show_workzone_callback );
2958 ShowSizeExportCaller g_show_size_caller;
2959 Callback<void(const Callback<void(bool)> &)> g_show_size_callback( g_show_size_caller );
2960 ToggleItem g_show_size( g_show_size_callback );
2962 ShowCrosshairExportCaller g_show_crosshair_caller;
2963 Callback<void(const Callback<void(bool)> &)> g_show_crosshair_callback( g_show_crosshair_caller );
2964 ToggleItem g_show_crosshair( g_show_crosshair_callback );
2966 ShowGridExportCaller g_show_grid_caller;
2967 Callback<void(const Callback<void(bool)> &)> g_show_grid_callback( g_show_grid_caller );
2968 ToggleItem g_show_grid( g_show_grid_callback );
2971 void XYShow_registerCommands(){
2972 GlobalToggles_insert( "ToggleSizePaint", ShowSizeToggleCaller(), ToggleItem::AddCallbackCaller( g_show_size ), Accelerator( 'J' ) );
2973 GlobalToggles_insert( "ToggleCrosshairs", ShowCrosshairToggleCaller(), ToggleItem::AddCallbackCaller( g_show_crosshair ), Accelerator( 'X', (GdkModifierType)GDK_SHIFT_MASK ) );
2974 GlobalToggles_insert( "ToggleGrid", ShowGridToggleCaller(), ToggleItem::AddCallbackCaller( g_show_grid ), Accelerator( '0' ) );
2976 GlobalToggles_insert( "ShowAngles", ShowAnglesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_angles ) );
2977 GlobalToggles_insert( "ShowNames", ShowNamesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_names ) );
2978 GlobalToggles_insert( "ShowBlocks", ShowBlocksToggleCaller(), ToggleItem::AddCallbackCaller( g_show_blocks ) );
2979 GlobalToggles_insert( "ShowCoordinates", ShowCoordinatesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_coordinates ) );
2980 GlobalToggles_insert( "ShowWindowOutline", ShowOutlineToggleCaller(), ToggleItem::AddCallbackCaller( g_show_outline ) );
2981 GlobalToggles_insert( "ShowAxes", ShowAxesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_axes ) );
2982 GlobalToggles_insert( "ShowWorkzone", ShowWorkzoneToggleCaller(), ToggleItem::AddCallbackCaller( g_show_workzone ) );
2985 void XYWnd_registerShortcuts(){
2986 command_connect_accelerator( "ToggleCrosshairs" );
2987 command_connect_accelerator( "ToggleSizePaint" );
2992 void Orthographic_constructPreferences( PreferencesPage& page ){
2993 page.appendCheckBox( "", "Solid selection boxes ( no stipple )", g_xywindow_globals.m_bNoStipple );
2994 //page.appendCheckBox( "", "Display size info", g_xywindow_globals_private.m_bSizePaint );
2995 page.appendCheckBox( "", "Chase mouse during drags", g_xywindow_globals_private.m_bChaseMouse );
2996 page.appendCheckBox( "", "Update views on camera move", g_xywindow_globals_private.m_bCamXYUpdate );
2998 void Orthographic_constructPage( PreferenceGroup& group ){
2999 PreferencesPage page( group.createPage( "Orthographic", "Orthographic View Preferences" ) );
3000 Orthographic_constructPreferences( page );
3002 void Orthographic_registerPreferencesPage(){
3003 PreferencesDialog_addSettingsPage( makeCallbackF(Orthographic_constructPage) );
3006 void Clipper_constructPreferences( PreferencesPage& page ){
3007 page.appendCheckBox( "", "Clipper tool uses caulk", g_clip_useCaulk );
3009 void Clipper_constructPage( PreferenceGroup& group ){
3010 PreferencesPage page( group.createPage( "Clipper", "Clipper Tool Settings" ) );
3011 Clipper_constructPreferences( page );
3013 void Clipper_registerPreferencesPage(){
3014 PreferencesDialog_addSettingsPage( makeCallbackF(Clipper_constructPage) );
3018 #include "preferencesystem.h"
3019 #include "stringio.h"
3022 struct ToggleShown_Bool {
3023 static void Export(const ToggleShown &self, const Callback<void(bool)> &returnz) {
3024 returnz(self.active());
3027 static void Import(ToggleShown &self, bool value) {
3033 void XYWindow_Construct(){
3034 // GlobalCommands_insert( "ToggleCrosshairs", makeCallbackF(ToggleShowCrosshair), Accelerator( 'X', (GdkModifierType)GDK_SHIFT_MASK ) );
3035 // GlobalCommands_insert( "ToggleSizePaint", makeCallbackF(ToggleShowSizeInfo), Accelerator( 'J' ) );
3036 // GlobalCommands_insert( "ToggleGrid", makeCallbackF(ToggleShowGrid), Accelerator( '0' ) );
3038 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 ) ) );
3039 GlobalToggles_insert( "ToggleSideView", ToggleShown::ToggleCaller( g_yz_side_shown ), ToggleItem::AddCallbackCaller( g_yz_side_shown.m_item ) );
3040 GlobalToggles_insert( "ToggleFrontView", ToggleShown::ToggleCaller( g_xz_front_shown ), ToggleItem::AddCallbackCaller( g_xz_front_shown.m_item ) );
3041 GlobalCommands_insert( "NextView", makeCallbackF(XY_Next), Accelerator( GDK_KEY_Tab, (GdkModifierType)GDK_CONTROL_MASK ) ); // fixme: doesn't show its shortcut
3042 GlobalCommands_insert( "ZoomIn", makeCallbackF(XY_ZoomIn), Accelerator( GDK_KEY_Delete ) );
3043 GlobalCommands_insert( "ZoomOut", makeCallbackF(XY_ZoomOut), Accelerator( GDK_KEY_Insert ) );
3044 GlobalCommands_insert( "ViewTop", makeCallbackF(XY_Top), Accelerator( GDK_KEY_KP_Home ) );
3045 GlobalCommands_insert( "ViewSide", makeCallbackF(XY_Side), Accelerator( GDK_KEY_KP_Page_Down ) );
3046 GlobalCommands_insert( "ViewFront", makeCallbackF(XY_Front), Accelerator( GDK_KEY_KP_End ) );
3047 GlobalCommands_insert( "Zoom100", makeCallbackF(XY_Zoom100) );
3048 GlobalCommands_insert( "CenterXYView", makeCallbackF(XY_Focus), Accelerator( GDK_KEY_Tab, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
3050 GlobalPreferenceSystem().registerPreference( "ClipCaulk", make_property_string( g_clip_useCaulk ) );
3052 GlobalPreferenceSystem().registerPreference( "NewRightClick", make_property_string( g_xywindow_globals.m_bRightClick ) );
3053 GlobalPreferenceSystem().registerPreference( "ImprovedWheelZoom", make_property_string( g_xywindow_globals.m_bImprovedWheelZoom ) );
3054 GlobalPreferenceSystem().registerPreference( "ChaseMouse", make_property_string( g_xywindow_globals_private.m_bChaseMouse ) );
3055 GlobalPreferenceSystem().registerPreference( "SizePainting", make_property_string( g_xywindow_globals_private.m_bSizePaint ) );
3056 GlobalPreferenceSystem().registerPreference( "ShowCrosshair", make_property_string( g_xywindow_globals_private.g_bCrossHairs ) );
3057 GlobalPreferenceSystem().registerPreference( "NoStipple", make_property_string( g_xywindow_globals.m_bNoStipple ) );
3058 GlobalPreferenceSystem().registerPreference( "SI_ShowCoords", make_property_string( g_xywindow_globals_private.show_coordinates ) );
3059 GlobalPreferenceSystem().registerPreference( "SI_ShowOutlines", make_property_string( g_xywindow_globals_private.show_outline ) );
3060 GlobalPreferenceSystem().registerPreference( "SI_ShowAxis", make_property_string( g_xywindow_globals_private.show_axis ) );
3061 GlobalPreferenceSystem().registerPreference( "CamXYUpdate", make_property_string( g_xywindow_globals_private.m_bCamXYUpdate ) );
3062 GlobalPreferenceSystem().registerPreference( "ShowWorkzone", make_property_string( g_xywindow_globals_private.d_show_work ) );
3064 GlobalPreferenceSystem().registerPreference( "SI_AxisColors0", make_property_string( g_xywindow_globals.AxisColorX ) );
3065 GlobalPreferenceSystem().registerPreference( "SI_AxisColors1", make_property_string( g_xywindow_globals.AxisColorY ) );
3066 GlobalPreferenceSystem().registerPreference( "SI_AxisColors2", make_property_string( g_xywindow_globals.AxisColorZ ) );
3067 GlobalPreferenceSystem().registerPreference( "SI_Colors1", make_property_string( g_xywindow_globals.color_gridback ) );
3068 GlobalPreferenceSystem().registerPreference( "SI_Colors2", make_property_string( g_xywindow_globals.color_gridminor ) );
3069 GlobalPreferenceSystem().registerPreference( "SI_Colors3", make_property_string( g_xywindow_globals.color_gridmajor ) );
3070 GlobalPreferenceSystem().registerPreference( "SI_Colors6", make_property_string( g_xywindow_globals.color_gridblock ) );
3071 GlobalPreferenceSystem().registerPreference( "SI_Colors7", make_property_string( g_xywindow_globals.color_gridtext ) );
3072 GlobalPreferenceSystem().registerPreference( "SI_Colors8", make_property_string( g_xywindow_globals.color_brushes ) );
3073 GlobalPreferenceSystem().registerPreference( "SI_Colors9", make_property_string( g_xywindow_globals.color_viewname ) );
3074 GlobalPreferenceSystem().registerPreference( "SI_Colors10", make_property_string( g_xywindow_globals.color_clipper ) );
3075 GlobalPreferenceSystem().registerPreference( "SI_Colors11", make_property_string( g_xywindow_globals.color_selbrushes ) );
3080 GlobalPreferenceSystem().registerPreference( "XZVIS", make_property_string<ToggleShown_Bool>( g_xz_front_shown ) );
3081 GlobalPreferenceSystem().registerPreference( "YZVIS", make_property_string<ToggleShown_Bool>( g_yz_side_shown ) );
3083 Orthographic_registerPreferencesPage();
3084 Clipper_registerPreferencesPage();
3086 XYWnd::captureStates();
3087 GlobalEntityClassManager().attach( g_EntityClassMenu );
3090 void XYWindow_Destroy(){
3091 GlobalEntityClassManager().detach( g_EntityClassMenu );
3092 XYWnd::releaseStates();