2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 // Leonardo Zide (leo@lokigames.com)
30 #include "debugging/debugging.h"
37 #include "ifilesystem.h"
40 #include "gtkutil/messagebox.h"
42 #include <gtk/gtklabel.h>
43 #include <gtk/gtkmenuitem.h>
45 #include "generic/callback.h"
46 #include "string/string.h"
47 #include "stream/stringstream.h"
50 #include "eclasslib.h"
52 #include "moduleobserver.h"
54 #include "gtkutil/menu.h"
55 #include "gtkutil/container.h"
56 #include "gtkutil/widget.h"
57 #include "gtkutil/glwidget.h"
58 #include "gtkutil/filechooser.h"
62 #include "brushmanip.h"
63 #include "selection.h"
65 #include "camwindow.h"
66 #include "texwindow.h"
67 #include "mainframe.h"
68 #include "preferences.h"
72 #include "windowobservers.h"
74 void LoadTextureRGBA( qtexture_t* q, unsigned char* pPixels, int nWidth, int nHeight );
77 extern bool g_brush_always_caulk;
83 Vector3 m_ptClip; // the 3d point
90 m_ptClip[0] = m_ptClip[1] = m_ptClip[2] = 0.0;
104 /*! Draw clip/path point with rasterized number label */
105 void Draw( int num, float scale );
106 /*! Draw clip/path point with rasterized string label */
107 void Draw( const char *label, float scale );
110 VIEWTYPE g_clip_viewtype;
111 bool g_bSwitch = true;
112 bool g_clip_useCaulk = false;
113 bool g_quick_clipper = false;
117 ClipPoint* g_pMovingClip = 0;
119 /* Drawing clip points */
120 void ClipPoint::Draw( int num, float scale ){
121 StringOutputStream label( 4 );
123 Draw( label.c_str(), scale );
126 void ClipPoint::Draw( const char *label, float scale ){
129 glColor3fv( vector3_to_array( g_xywindow_globals.color_clipper ) );
130 glBegin( GL_POINTS );
131 glVertex3fv( vector3_to_array( m_ptClip ) );
135 float offset = 2.0f / scale;
138 glRasterPos3f( m_ptClip[0] + offset, m_ptClip[1] + offset, m_ptClip[2] + offset );
139 glCallLists( GLsizei( strlen( label ) ), GL_UNSIGNED_BYTE, label );
142 float fDiff( float f1, float f2 ){
151 inline double ClipPoint_Intersect( const ClipPoint& clip, const Vector3& point, VIEWTYPE viewtype, float scale ){
152 int nDim1 = ( viewtype == YZ ) ? 1 : 0;
153 int nDim2 = ( viewtype == XY ) ? 1 : 2;
154 double screenDistanceSquared( vector2_length_squared( Vector2( fDiff( clip.m_ptClip[nDim1], point[nDim1] ) * scale, fDiff( clip.m_ptClip[nDim2], point[nDim2] ) * scale ) ) );
155 if ( screenDistanceSquared < 8 * 8 ) {
156 return screenDistanceSquared;
161 inline void ClipPoint_testSelect( ClipPoint& clip, const Vector3& point, VIEWTYPE viewtype, float scale, double& bestDistance, ClipPoint*& bestClip ){
163 double distance = ClipPoint_Intersect( clip, point, viewtype, scale );
164 if ( distance < bestDistance ) {
165 bestDistance = distance;
171 inline ClipPoint* GlobalClipPoints_Find( const Vector3& point, VIEWTYPE viewtype, float scale ){
172 double bestDistance = FLT_MAX;
173 ClipPoint* bestClip = 0;
174 ClipPoint_testSelect( g_Clip1, point, viewtype, scale, bestDistance, bestClip );
175 ClipPoint_testSelect( g_Clip2, point, viewtype, scale, bestDistance, bestClip );
176 ClipPoint_testSelect( g_Clip3, point, viewtype, scale, bestDistance, bestClip );
180 inline void GlobalClipPoints_Draw( float scale ){
182 if ( g_Clip1.Set() ) {
183 g_Clip1.Draw( 1, scale );
185 if ( g_Clip2.Set() ) {
186 g_Clip2.Draw( 2, scale );
188 if ( g_Clip3.Set() ) {
189 g_Clip3.Draw( 3, scale );
193 inline bool GlobalClipPoints_valid(){
194 return g_Clip1.Set() && g_Clip2.Set();
197 void PlanePointsFromClipPoints( Vector3 planepts[3], const AABB& bounds, int viewtype ){
198 ASSERT_MESSAGE( GlobalClipPoints_valid(), "clipper points not initialised" );
199 planepts[0] = g_Clip1.m_ptClip;
200 planepts[1] = g_Clip2.m_ptClip;
201 planepts[2] = g_Clip3.m_ptClip;
202 Vector3 maxs( vector3_added( bounds.origin, bounds.extents ) );
203 Vector3 mins( vector3_subtracted( bounds.origin, bounds.extents ) );
204 if ( !g_Clip3.Set() ) {
205 int n = ( viewtype == XY ) ? 2 : ( viewtype == YZ ) ? 0 : 1;
206 int x = ( n == 0 ) ? 1 : 0;
207 int y = ( n == 2 ) ? 1 : 2;
209 if ( n == 1 ) { // on viewtype XZ, flip clip points
210 planepts[0][n] = maxs[n];
211 planepts[1][n] = maxs[n];
212 planepts[2][x] = g_Clip1.m_ptClip[x];
213 planepts[2][y] = g_Clip1.m_ptClip[y];
214 planepts[2][n] = mins[n];
218 planepts[0][n] = mins[n];
219 planepts[1][n] = mins[n];
220 planepts[2][x] = g_Clip1.m_ptClip[x];
221 planepts[2][y] = g_Clip1.m_ptClip[y];
222 planepts[2][n] = maxs[n];
229 if ( !GlobalClipPoints_valid() ) {
230 planepts[0] = Vector3( 0, 0, 0 );
231 planepts[1] = Vector3( 0, 0, 0 );
232 planepts[2] = Vector3( 0, 0, 0 );
233 Scene_BrushSetClipPlane( GlobalSceneGraph(), Plane3( 0, 0, 0, 0 ) );
237 AABB bounds( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) );
238 PlanePointsFromClipPoints( planepts, bounds, g_clip_viewtype );
240 std::swap( planepts[0], planepts[1] );
242 Scene_BrushSetClipPlane( GlobalSceneGraph(), plane3_for_points( planepts[0], planepts[1], planepts[2] ) );
244 ClipperChangeNotify();
247 const char* Clip_getShader(){
248 return g_clip_useCaulk ? "textures/common/caulk" : TextureBrowser_GetSelectedShader( GlobalTextureBrowser() );
252 if ( ClipMode() && GlobalClipPoints_valid() ) {
254 AABB bounds( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) );
255 PlanePointsFromClipPoints( planepts, bounds, g_clip_viewtype );
256 Scene_BrushSplitByPlane( GlobalSceneGraph(), planepts[0], planepts[1], planepts[2], Clip_getShader(), ( !g_bSwitch ) ? eFront : eBack );
261 ClipperChangeNotify();
262 if( g_quick_clipper ){
263 g_quick_clipper = false;
270 if ( ClipMode() && GlobalClipPoints_valid() ) {
272 AABB bounds( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) );
273 PlanePointsFromClipPoints( planepts, bounds, g_clip_viewtype );
274 Scene_BrushSplitByPlane( GlobalSceneGraph(), planepts[0], planepts[1], planepts[2], Clip_getShader(), eFrontAndBack );
279 ClipperChangeNotify();
280 if( g_quick_clipper ){
281 g_quick_clipper = false;
288 g_bSwitch = !g_bSwitch;
290 ClipperChangeNotify();
293 void OnClipMode( bool enabled ){
298 if ( !enabled && g_pMovingClip ) {
303 ClipperChangeNotify();
307 return GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eClip;
310 void NewClipPoint( const Vector3& point ){
311 if ( g_Clip1.Set() == false ) {
312 g_Clip1.m_ptClip = point;
315 else if ( g_Clip2.Set() == false ) {
316 g_Clip2.m_ptClip = point;
319 else if ( g_Clip3.Set() == false ) {
320 g_Clip3.m_ptClip = point;
328 g_Clip1.m_ptClip = point;
333 ClipperChangeNotify();
338 struct xywindow_globals_private_t
342 // these are in the View > Show menu with Show coordinates
344 bool show_coordinates;
358 xywindow_globals_private_t() :
362 show_coordinates( false ),
364 show_outline( true ),
367 d_show_work( false ),
369 show_blocks( false ),
371 m_bCamXYUpdate( true ),
372 m_bChaseMouse( true ),
373 m_bSizePaint( true ){
378 xywindow_globals_t g_xywindow_globals;
379 xywindow_globals_private_t g_xywindow_globals_private;
381 const unsigned int RAD_NONE = 0x00;
382 const unsigned int RAD_SHIFT = 0x01;
383 const unsigned int RAD_ALT = 0x02;
384 const unsigned int RAD_CONTROL = 0x04;
385 const unsigned int RAD_PRESS = 0x08;
386 const unsigned int RAD_LBUTTON = 0x10;
387 const unsigned int RAD_MBUTTON = 0x20;
388 const unsigned int RAD_RBUTTON = 0x40;
390 inline ButtonIdentifier button_for_flags( unsigned int flags ){
391 if ( flags & RAD_LBUTTON ) {
394 if ( flags & RAD_RBUTTON ) {
395 return c_buttonRight;
397 if ( flags & RAD_MBUTTON ) {
398 return c_buttonMiddle;
400 return c_buttonInvalid;
403 inline ModifierFlags modifiers_for_flags( unsigned int flags ){
404 ModifierFlags modifiers = c_modifierNone;
405 if ( flags & RAD_SHIFT ) {
406 modifiers |= c_modifierShift;
408 if ( flags & RAD_CONTROL ) {
409 modifiers |= c_modifierControl;
411 if ( flags & RAD_ALT ) {
412 modifiers |= c_modifierAlt;
417 inline unsigned int buttons_for_button_and_modifiers( ButtonIdentifier button, ModifierFlags flags ){
418 unsigned int buttons = 0;
420 switch ( button.get() )
422 case ButtonEnumeration::LEFT: buttons |= RAD_LBUTTON; break;
423 case ButtonEnumeration::MIDDLE: buttons |= RAD_MBUTTON; break;
424 case ButtonEnumeration::RIGHT: buttons |= RAD_RBUTTON; break;
427 if ( bitfield_enabled( flags, c_modifierControl ) ) {
428 buttons |= RAD_CONTROL;
431 if ( bitfield_enabled( flags, c_modifierShift ) ) {
432 buttons |= RAD_SHIFT;
435 if ( bitfield_enabled( flags, c_modifierAlt ) ) {
442 inline unsigned int buttons_for_event_button( GdkEventButton* event ){
443 unsigned int flags = 0;
445 switch ( event->button )
447 case 1: flags |= RAD_LBUTTON; break;
448 case 2: flags |= RAD_MBUTTON; break;
449 case 3: flags |= RAD_RBUTTON; break;
452 if ( ( event->state & GDK_CONTROL_MASK ) != 0 ) {
453 flags |= RAD_CONTROL;
456 if ( ( event->state & GDK_SHIFT_MASK ) != 0 ) {
460 if ( ( event->state & GDK_MOD1_MASK ) != 0 ) {
467 inline unsigned int buttons_for_state( guint state ){
468 unsigned int flags = 0;
470 if ( ( state & GDK_BUTTON1_MASK ) != 0 ) {
471 flags |= RAD_LBUTTON;
474 if ( ( state & GDK_BUTTON2_MASK ) != 0 ) {
475 flags |= RAD_MBUTTON;
478 if ( ( state & GDK_BUTTON3_MASK ) != 0 ) {
479 flags |= RAD_RBUTTON;
482 if ( ( state & GDK_CONTROL_MASK ) != 0 ) {
483 flags |= RAD_CONTROL;
486 if ( ( state & GDK_SHIFT_MASK ) != 0 ) {
490 if ( ( state & GDK_MOD1_MASK ) != 0 ) {
498 void XYWnd::SetScale( float f ){
502 XYWnd_Update( *this );
505 void XYWnd::ZoomIn(){
506 float max_scale = 64;
507 float scale = Scale() * 5.0f / 4.0f;
508 if ( scale > max_scale ) {
509 if ( Scale() != max_scale ) {
510 SetScale( max_scale );
520 // NOTE: the zoom out factor is 4/5, we could think about customizing it
521 // we don't go below a zoom factor corresponding to 10% of the max world size
522 // (this has to be computed against the window size)
523 void XYWnd::ZoomOut(){
524 float min_scale = MIN( Width(), Height() ) / ( 1.1f * ( g_MaxWorldCoord - g_MinWorldCoord ) );
525 float scale = Scale() * 4.0f / 5.0f;
526 if ( scale < min_scale ) {
527 if ( Scale() != min_scale ) {
528 SetScale( min_scale );
537 void XYWnd::ZoomInWithMouse( int pointx, int pointy ){
538 float old_scale = Scale();
540 if ( g_xywindow_globals.m_bImprovedWheelZoom ) {
541 float scale_diff = 1.0 / old_scale - 1.0 / Scale();
542 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
543 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
544 Vector3 origin = GetOrigin();
545 origin[nDim1] += scale_diff * (pointx - 0.5 * Width());
546 origin[nDim2] -= scale_diff * (pointy - 0.5 * Height());
551 VIEWTYPE GlobalXYWnd_getCurrentViewType(){
552 ASSERT_NOTNULL( g_pParentWnd );
553 ASSERT_NOTNULL( g_pParentWnd->ActiveXY() );
554 return g_pParentWnd->ActiveXY()->GetViewType();
557 // =============================================================================
560 bool g_bCrossHairs = false;
562 GtkMenu* XYWnd::m_mnuDrop = 0;
564 // this is disabled, and broken
565 // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=394
569 width = g_pParentWnd->ActiveXY()->Width();
570 height = g_pParentWnd->ActiveXY()->Height();
572 const char* filename;
574 filename = file_dialog( GTK_WIDGET( MainFrame_getWindow() ), FALSE, "Save Image", 0, FILTER_BMP );
579 g_pParentWnd->ActiveXY()->MakeCurrent();
580 img = (unsigned char*)malloc( width * height * 3 );
581 glReadPixels( 0,0,width,height,GL_RGB,GL_UNSIGNED_BYTE,img );
584 fp = fopen( filename, "wb" );
587 unsigned long cmap, bfSize;
591 bfSize = 54 + width * height * 3;
593 long byteswritten = 0;
594 long pixoff = 54 + cmap * 4;
596 char m1 = 'B', m2 = 'M';
597 fwrite( &m1, 1, 1, fp ); byteswritten++; // B
598 fwrite( &m2, 1, 1, fp ); byteswritten++; // M
599 fwrite( &bfSize, 4, 1, fp ); byteswritten += 4; // bfSize
600 fwrite( &res, 2, 1, fp ); byteswritten += 2; // bfReserved1
601 fwrite( &res, 2, 1, fp ); byteswritten += 2; // bfReserved2
602 fwrite( &pixoff, 4, 1, fp ); byteswritten += 4; // bfOffBits
604 unsigned long biSize = 40, compress = 0, size = 0;
606 unsigned short planes = 1;
607 fwrite( &biSize, 4, 1, fp ); byteswritten += 4; // biSize
608 fwrite( &width, 4, 1, fp ); byteswritten += 4; // biWidth
609 fwrite( &height, 4, 1, fp ); byteswritten += 4; // biHeight
610 fwrite( &planes, 2, 1, fp ); byteswritten += 2; // biPlanes
611 fwrite( &bits, 2, 1, fp ); byteswritten += 2; // biBitCount
612 fwrite( &compress, 4, 1, fp ); byteswritten += 4; // biCompression
613 fwrite( &size, 4, 1, fp ); byteswritten += 4; // biSizeImage
614 fwrite( &pixels, 4, 1, fp ); byteswritten += 4; // biXPelsPerMeter
615 fwrite( &pixels, 4, 1, fp ); byteswritten += 4; // biYPelsPerMeter
616 fwrite( &cmap, 4, 1, fp ); byteswritten += 4; // biClrUsed
617 fwrite( &cmap, 4, 1, fp ); byteswritten += 4; // biClrImportant
619 unsigned long widthDW = ( ( ( width * 24 ) + 31 ) / 32 * 4 );
620 long row, row_size = width * 3;
621 for ( row = 0; row < height; row++ )
623 unsigned char* buf = img + row * row_size;
627 for ( col = 0; col < row_size; col += 3 )
629 putc( buf[col + 2], fp );
630 putc( buf[col + 1], fp );
631 putc( buf[col], fp );
633 byteswritten += row_size;
636 for ( count = row_size; count < widthDW; count++ )
638 putc( 0, fp ); // dummy
653 Timer g_chasemouse_timer;
655 void XYWnd::ChaseMouse(){
656 float multiplier = g_chasemouse_timer.elapsed_msec() / 10.0f;
657 Scroll( float_to_integer( multiplier * m_chasemouse_delta_x ), float_to_integer( multiplier * -m_chasemouse_delta_y ) );
659 //globalOutputStream() << "chasemouse: multiplier=" << multiplier << " x=" << m_chasemouse_delta_x << " y=" << m_chasemouse_delta_y << '\n';
661 XY_MouseMoved( m_chasemouse_current_x, m_chasemouse_current_y, getButtonState() );
662 g_chasemouse_timer.start();
665 gboolean xywnd_chasemouse( gpointer data ){
666 reinterpret_cast<XYWnd*>( data )->ChaseMouse();
670 inline const int& min_int( const int& left, const int& right ){
671 return std::min( left, right );
674 bool XYWnd::chaseMouseMotion( int pointx, int pointy ){
675 m_chasemouse_delta_x = 0;
676 m_chasemouse_delta_y = 0;
678 if ( g_xywindow_globals_private.m_bChaseMouse && getButtonState() == RAD_LBUTTON ) {
679 const int epsilon = 16;
681 if ( pointx < epsilon ) {
682 m_chasemouse_delta_x = std::max( pointx, 0 ) - epsilon;
684 else if ( ( pointx - m_nWidth ) > -epsilon ) {
685 m_chasemouse_delta_x = min_int( ( pointx - m_nWidth ), 0 ) + epsilon;
688 if ( pointy < epsilon ) {
689 m_chasemouse_delta_y = std::max( pointy, 0 ) - epsilon;
691 else if ( ( pointy - m_nHeight ) > -epsilon ) {
692 m_chasemouse_delta_y = min_int( ( pointy - m_nHeight ), 0 ) + epsilon;
695 if ( m_chasemouse_delta_y != 0 || m_chasemouse_delta_x != 0 ) {
696 //globalOutputStream() << "chasemouse motion: x=" << pointx << " y=" << pointy << "... ";
697 m_chasemouse_current_x = pointx;
698 m_chasemouse_current_y = pointy;
699 if ( m_chasemouse_handler == 0 ) {
700 //globalOutputStream() << "chasemouse timer start... ";
701 g_chasemouse_timer.start();
702 m_chasemouse_handler = g_idle_add( xywnd_chasemouse, this );
708 if ( m_chasemouse_handler != 0 ) {
709 //globalOutputStream() << "chasemouse cancel\n";
710 g_source_remove( m_chasemouse_handler );
711 m_chasemouse_handler = 0;
717 if ( m_chasemouse_handler != 0 ) {
718 //globalOutputStream() << "chasemouse cancel\n";
719 g_source_remove( m_chasemouse_handler );
720 m_chasemouse_handler = 0;
726 // =============================================================================
728 Shader* XYWnd::m_state_selected = 0;
730 void xy_update_xor_rectangle( XYWnd& self, rect_t area ){
731 if ( GTK_WIDGET_VISIBLE( self.GetWidget() ) ) {
732 rectangle_t rect = rectangle_from_area( area.min, area.max, self.Width(), self.Height() );
733 // int nDim1 = ( self.GetViewType() == YZ ) ? 1 : 0;
734 // int nDim2 = ( self.GetViewType() == XY ) ? 1 : 2;
735 // rect.x /= self.Scale();
736 // rect.y /= self.Scale();
737 // rect.w /= self.Scale();
738 // rect.h /= self.Scale();
739 // rect.x += self.GetOrigin()[nDim1];
740 // rect.y += self.GetOrigin()[nDim2];
741 self.m_XORRectangle.set( rect );
745 gboolean xywnd_button_press( GtkWidget* widget, GdkEventButton* event, XYWnd* xywnd ){
746 if ( event->type == GDK_BUTTON_PRESS ) {
747 if( !xywnd->Active() ){
748 g_pParentWnd->SetActiveXY( xywnd );
751 xywnd->ButtonState_onMouseDown( buttons_for_event_button( event ) );
753 xywnd->onMouseDown( WindowVector( event->x, event->y ), button_for_button( event->button ), modifiers_for_state( event->state ) );
758 gboolean xywnd_button_release( GtkWidget* widget, GdkEventButton* event, XYWnd* xywnd ){
759 if ( event->type == GDK_BUTTON_RELEASE ) {
760 xywnd->XY_MouseUp( static_cast<int>( event->x ), static_cast<int>( event->y ), buttons_for_event_button( event ) );
762 xywnd->ButtonState_onMouseUp( buttons_for_event_button( event ) );
767 gboolean xywnd_focus_in( GtkWidget* widget, GdkEventFocus* event, XYWnd* xywnd ){
768 if ( event->type == GDK_FOCUS_CHANGE ) {
770 if( !xywnd->Active() ){
771 g_pParentWnd->SetActiveXY( xywnd );
778 void xywnd_motion( gdouble x, gdouble y, guint state, void* data ){
779 if ( reinterpret_cast<XYWnd*>( data )->chaseMouseMotion( static_cast<int>( x ), static_cast<int>( y ) ) ) {
782 reinterpret_cast<XYWnd*>( data )->XY_MouseMoved( static_cast<int>( x ), static_cast<int>( y ), buttons_for_state( state ) );
785 gboolean xywnd_wheel_scroll( GtkWidget* widget, GdkEventScroll* event, XYWnd* xywnd ){
786 if( !xywnd->Active() ){
787 g_pParentWnd->SetActiveXY( xywnd );
789 if ( event->direction == GDK_SCROLL_UP ) {
790 xywnd->ZoomInWithMouse( (int)event->x, (int)event->y );
792 else if ( event->direction == GDK_SCROLL_DOWN ) {
798 gboolean xywnd_size_allocate( GtkWidget* widget, GtkAllocation* allocation, XYWnd* xywnd ){
799 xywnd->m_nWidth = allocation->width;
800 xywnd->m_nHeight = allocation->height;
801 xywnd->updateProjection();
802 xywnd->m_window_observer->onSizeChanged( xywnd->Width(), xywnd->Height() );
806 gboolean xywnd_expose( GtkWidget* widget, GdkEventExpose* event, XYWnd* xywnd ){
807 if ( glwidget_make_current( xywnd->GetWidget() ) != FALSE ) {
808 if ( Map_Valid( g_map ) && ScreenUpdates_Enabled() ) {
809 GlobalOpenGL_debugAssertNoErrors();
811 GlobalOpenGL_debugAssertNoErrors();
813 xywnd->m_XORRectangle.set( rectangle_t() );
815 glwidget_swap_buffers( xywnd->GetWidget() );
821 void XYWnd_CameraMoved( XYWnd& xywnd ){
822 if ( g_xywindow_globals_private.m_bCamXYUpdate ) {
823 //XYWnd_Update( xywnd );
824 xywnd.UpdateCameraIcon();
829 m_gl_widget( glwidget_new( FALSE ) ),
830 m_deferredDraw( WidgetQueueDrawCaller( *m_gl_widget ) ),
831 m_deferred_motion( xywnd_motion, this ),
833 m_window_observer( NewWindowObserver() ),
834 m_XORRectangle( m_gl_widget ),
835 m_chasemouse_handler( 0 ){
839 m_bNewBrushDrag = false;
840 m_move_started = false;
841 m_zoom_started = false;
852 m_backgroundActivated = false;
859 m_entityCreate = false;
863 GlobalWindowObservers_add( m_window_observer );
864 GlobalWindowObservers_connectWidget( m_gl_widget );
866 m_window_observer->setRectangleDrawCallback( ReferenceCaller1<XYWnd, rect_t, xy_update_xor_rectangle>( *this ) );
867 m_window_observer->setView( m_view );
869 gtk_widget_ref( m_gl_widget );
871 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 );
872 GTK_WIDGET_SET_FLAGS( m_gl_widget, GTK_CAN_FOCUS );
874 m_sizeHandler = g_signal_connect( G_OBJECT( m_gl_widget ), "size_allocate", G_CALLBACK( xywnd_size_allocate ), this );
875 m_exposeHandler = g_signal_connect( G_OBJECT( m_gl_widget ), "expose_event", G_CALLBACK( xywnd_expose ), this );
877 g_signal_connect( G_OBJECT( m_gl_widget ), "button_press_event", G_CALLBACK( xywnd_button_press ), this );
878 g_signal_connect( G_OBJECT( m_gl_widget ), "button_release_event", G_CALLBACK( xywnd_button_release ), this );
879 g_signal_connect( G_OBJECT( m_gl_widget ), "focus_in_event", G_CALLBACK( xywnd_focus_in ), this ); //works only in floating views layout
880 g_signal_connect( G_OBJECT( m_gl_widget ), "motion_notify_event", G_CALLBACK( DeferredMotion::gtk_motion ), &m_deferred_motion );
882 g_signal_connect( G_OBJECT( m_gl_widget ), "scroll_event", G_CALLBACK( xywnd_wheel_scroll ), this );
884 Map_addValidCallback( g_map, DeferredDrawOnMapValidChangedCaller( m_deferredDraw ) );
889 AddSceneChangeCallback( ReferenceCaller<XYWnd, &XYWnd_Update>( *this ) );
890 AddCameraMovedCallback( ReferenceCaller<XYWnd, &XYWnd_CameraMoved>( *this ) );
892 PressedButtons_connect( g_pressedButtons, m_gl_widget );
894 onMouseDown.connectLast( makeSignalHandler3( MouseDownCaller(), *this ) );
900 if ( m_mnuDrop != 0 ) {
901 gtk_widget_destroy( GTK_WIDGET( m_mnuDrop ) );
905 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_sizeHandler );
906 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_exposeHandler );
908 gtk_widget_unref( m_gl_widget );
910 m_window_observer->release();
913 void XYWnd::captureStates(){
914 m_state_selected = GlobalShaderCache().capture( "$XY_OVERLAY" );
917 void XYWnd::releaseStates(){
918 GlobalShaderCache().release( "$XY_OVERLAY" );
921 const Vector3& XYWnd::GetOrigin(){
925 void XYWnd::SetOrigin( const Vector3& origin ){
930 void XYWnd::Scroll( int x, int y ){
931 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
932 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
933 m_vOrigin[nDim1] += x / m_fScale;
934 m_vOrigin[nDim2] += y / m_fScale;
939 unsigned int Clipper_buttons(){
943 unsigned int Clipper_quick_buttons(){
944 return RAD_LBUTTON | RAD_CONTROL;
947 void XYWnd::DropClipPoint( int pointx, int pointy ){
950 XY_ToPoint( pointx, pointy, point );
953 Select_GetMid( mid );
954 g_clip_viewtype = static_cast<VIEWTYPE>( GetViewType() );
955 const int nDim = ( g_clip_viewtype == YZ ) ? 0 : ( ( g_clip_viewtype == XZ ) ? 1 : 2 );
956 point[nDim] = mid[nDim];
957 vector3_snap( point, GetSnapGridSize() );
958 NewClipPoint( point );
961 void XYWnd::Clipper_OnLButtonDown( int x, int y ){
962 Vector3 mousePosition;
963 XY_ToPoint( x, y, mousePosition );
964 g_pMovingClip = GlobalClipPoints_Find( mousePosition, (VIEWTYPE)m_viewType, m_fScale );
965 if ( !g_pMovingClip ) {
966 DropClipPoint( x, y );
970 void XYWnd::Clipper_OnLButtonUp( int x, int y ){
971 if ( g_pMovingClip ) {
976 void XYWnd::Clipper_OnMouseMoved( int x, int y ){
977 if ( g_pMovingClip ) {
978 XY_ToPoint( x, y, g_pMovingClip->m_ptClip );
979 XY_SnapToGrid( g_pMovingClip->m_ptClip );
981 ClipperChangeNotify();
985 void XYWnd::Clipper_Crosshair_OnMouseMoved( int x, int y ){
986 Vector3 mousePosition;
987 XY_ToPoint( x, y, mousePosition );
988 if ( ClipMode() && GlobalClipPoints_Find( mousePosition, (VIEWTYPE)m_viewType, m_fScale ) != 0 ) {
990 cursor = gdk_cursor_new( GDK_CROSSHAIR );
991 gdk_window_set_cursor( m_gl_widget->window, cursor );
992 gdk_cursor_unref( cursor );
996 gdk_window_set_cursor( m_gl_widget->window, 0 );
1000 void XYWnd::SetCustomPivotOrigin( int pointx, int pointy ){
1002 XY_ToPoint( pointx, pointy, point );
1003 VIEWTYPE viewtype = static_cast<VIEWTYPE>( GetViewType() );
1004 const int nDim = ( viewtype == YZ ) ? 0 : ( ( viewtype == XZ ) ? 1 : 2 );
1005 //vector3_snap( point, GetSnapGridSize() );
1006 point[nDim] = 999999;
1008 GlobalSelectionSystem().setCustomPivotOrigin( point );
1009 SceneChangeNotify();
1012 unsigned int MoveCamera_buttons(){
1013 return RAD_CONTROL | ( g_glwindow_globals.m_nMouseType == ETwoButton ? RAD_RBUTTON : RAD_MBUTTON );
1016 void XYWnd_PositionCamera( XYWnd* xywnd, int x, int y, CamWnd& camwnd ){
1017 Vector3 origin( Camera_getOrigin( camwnd ) );
1018 xywnd->XY_ToPoint( x, y, origin );
1019 xywnd->XY_SnapToGrid( origin );
1020 Camera_setOrigin( camwnd, origin );
1023 unsigned int OrientCamera_buttons(){
1024 if ( g_glwindow_globals.m_nMouseType == ETwoButton ) {
1025 return RAD_RBUTTON | RAD_SHIFT | RAD_CONTROL;
1030 void XYWnd_OrientCamera( XYWnd* xywnd, int x, int y, CamWnd& camwnd ){
1031 Vector3 point = g_vector3_identity;
1032 xywnd->XY_ToPoint( x, y, point );
1033 xywnd->XY_SnapToGrid( point );
1034 vector3_subtract( point, Camera_getOrigin( camwnd ) );
1036 int n1 = ( xywnd->GetViewType() == XY ) ? 1 : 2;
1037 int n2 = ( xywnd->GetViewType() == YZ ) ? 1 : 0;
1038 int nAngle = ( xywnd->GetViewType() == XY ) ? CAMERA_YAW : CAMERA_PITCH;
1039 if ( point[n1] || point[n2] ) {
1040 Vector3 angles( Camera_getAngles( camwnd ) );
1041 angles[nAngle] = static_cast<float>( radians_to_degrees( atan2( point[n1], point[n2] ) ) );
1042 Camera_setAngles( camwnd, angles );
1046 unsigned int SetCustomPivotOrigin_buttons(){
1047 return RAD_MBUTTON | RAD_SHIFT;
1055 unsigned int NewBrushDrag_buttons(){
1059 void XYWnd::NewBrushDrag_Begin( int x, int y ){
1061 m_nNewBrushPressx = x;
1062 m_nNewBrushPressy = y;
1064 m_bNewBrushDrag = true;
1065 GlobalUndoSystem().start();
1068 void XYWnd::NewBrushDrag_End( int x, int y ){
1069 if ( m_NewBrushDrag != 0 ) {
1070 GlobalUndoSystem().finish( "brushDragNew" );
1074 void XYWnd::NewBrushDrag( int x, int y ){
1076 XY_ToPoint( m_nNewBrushPressx, m_nNewBrushPressy, mins );
1077 XY_SnapToGrid( mins );
1078 XY_ToPoint( x, y, maxs );
1079 XY_SnapToGrid( maxs );
1081 int nDim = ( m_viewType == XY ) ? 2 : ( m_viewType == YZ ) ? 0 : 1;
1083 mins[nDim] = float_snapped( Select_getWorkZone().d_work_min[nDim], GetSnapGridSize() );
1084 maxs[nDim] = float_snapped( Select_getWorkZone().d_work_max[nDim], GetSnapGridSize() );
1086 if ( maxs[nDim] <= mins[nDim] ) {
1087 maxs[nDim] = mins[nDim] + GetGridSize();
1090 for ( int i = 0 ; i < 3 ; i++ )
1092 if ( mins[i] == maxs[i] ) {
1093 return; // don't create a degenerate brush
1095 if ( mins[i] > maxs[i] ) {
1096 float temp = mins[i];
1102 if ( m_NewBrushDrag == 0 ) {
1103 NodeSmartReference node( GlobalBrushCreator().createBrush() );
1104 Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->insert( node );
1106 scene::Path brushpath( makeReference( GlobalSceneGraph().root() ) );
1107 brushpath.push( makeReference( *Map_GetWorldspawn( g_map ) ) );
1108 brushpath.push( makeReference( node.get() ) );
1109 selectPath( brushpath, true );
1111 m_NewBrushDrag = node.get_pointer();
1115 //Scene_BrushResize_Selected(GlobalSceneGraph(), aabb_for_minmax(mins, maxs), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()));
1116 Scene_BrushResize_Selected( GlobalSceneGraph(), aabb_for_minmax( mins, maxs ),
1117 g_brush_always_caulk ?
1118 "textures/common/caulk" : TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ) );
1121 void entitycreate_activated( GtkWidget* item ){
1122 scene::Node* world_node = Map_FindWorldspawn( g_map );
1123 const char* entity_name = gtk_label_get_text( GTK_LABEL( GTK_BIN( item )->child ) );
1125 if ( !( world_node && string_equal( entity_name, "worldspawn" ) ) ) {
1126 g_pParentWnd->ActiveXY()->OnEntityCreate( entity_name );
1129 GlobalRadiant().m_pfnMessageBox( GTK_WIDGET( MainFrame_getWindow() ), "There's already a worldspawn in your map!"
1137 void EntityClassMenu_addItem( GtkMenu* menu, const char* name ){
1138 GtkMenuItem* item = GTK_MENU_ITEM( gtk_menu_item_new_with_label( name ) );
1139 g_signal_connect( G_OBJECT( item ), "activate", G_CALLBACK( entitycreate_activated ), item );
1140 gtk_widget_show( GTK_WIDGET( item ) );
1141 menu_add_item( menu, item );
1144 class EntityClassMenuInserter : public EntityClassVisitor
1146 typedef std::pair<GtkMenu*, CopiedString> MenuPair;
1147 typedef std::vector<MenuPair> MenuStack;
1149 CopiedString m_previous;
1151 EntityClassMenuInserter( GtkMenu* menu ){
1152 m_stack.reserve( 2 );
1153 m_stack.push_back( MenuPair( menu, "" ) );
1155 ~EntityClassMenuInserter(){
1156 if ( !string_empty( m_previous.c_str() ) ) {
1157 addItem( m_previous.c_str(), "" );
1160 void visit( EntityClass* e ){
1161 ASSERT_MESSAGE( !string_empty( e->name() ), "entity-class has no name" );
1162 if ( !string_empty( m_previous.c_str() ) ) {
1163 addItem( m_previous.c_str(), e->name() );
1165 m_previous = e->name();
1167 void pushMenu( const CopiedString& name ){
1168 GtkMenuItem* item = GTK_MENU_ITEM( gtk_menu_item_new_with_label( name.c_str() ) );
1169 gtk_widget_show( GTK_WIDGET( item ) );
1170 container_add_widget( GTK_CONTAINER( m_stack.back().first ), GTK_WIDGET( item ) );
1172 GtkMenu* submenu = GTK_MENU( gtk_menu_new() );
1173 gtk_menu_item_set_submenu( item, GTK_WIDGET( submenu ) );
1175 m_stack.push_back( MenuPair( submenu, name ) );
1180 void addItem( const char* name, const char* next ){
1181 const char* underscore = strchr( name, '_' );
1183 if ( underscore != 0 && underscore != name ) {
1184 bool nextEqual = string_equal_n( name, next, ( underscore + 1 ) - name );
1185 const char* parent = m_stack.back().second.c_str();
1187 if ( !string_empty( parent )
1188 && string_length( parent ) == std::size_t( underscore - name )
1189 && string_equal_n( name, parent, underscore - name ) ) { // this is a child
1191 else if ( nextEqual ) {
1192 if ( m_stack.size() == 2 ) {
1195 pushMenu( CopiedString( StringRange( name, underscore ) ) );
1197 else if ( m_stack.size() == 2 ) {
1201 else if ( m_stack.size() == 2 ) {
1205 EntityClassMenu_addItem( m_stack.back().first, name );
1209 void XYWnd::OnContextMenu(){
1210 if ( g_xywindow_globals.m_bRightClick == false ) {
1214 if ( m_mnuDrop == 0 ) { // first time, load it up
1215 GtkMenu* menu = m_mnuDrop = GTK_MENU( gtk_menu_new() );
1217 EntityClassMenuInserter inserter( menu );
1218 GlobalEntityClassManager().forEach( inserter );
1221 gtk_menu_popup( m_mnuDrop, 0, 0, 0, 0, 1, GDK_CURRENT_TIME );
1224 FreezePointer g_xywnd_freezePointer;
1226 unsigned int Move_buttons(){
1230 void XYWnd_moveDelta( int x, int y, unsigned int state, void* data ){
1231 reinterpret_cast<XYWnd*>( data )->EntityCreate_MouseMove( x, y );
1232 reinterpret_cast<XYWnd*>( data )->Scroll( -x, y );
1235 gboolean XYWnd_Move_focusOut( GtkWidget* widget, GdkEventFocus* event, XYWnd* xywnd ){
1240 void XYWnd::Move_Begin(){
1241 if ( m_move_started ) {
1244 m_move_started = true;
1245 g_xywnd_freezePointer.freeze_pointer( m_parent != 0 ? m_parent : MainFrame_getWindow(), m_gl_widget, XYWnd_moveDelta, this );
1246 m_move_focusOut = g_signal_connect( G_OBJECT( m_gl_widget ), "focus_out_event", G_CALLBACK( XYWnd_Move_focusOut ), this );
1249 void XYWnd::Move_End(){
1250 m_move_started = false;
1251 g_xywnd_freezePointer.unfreeze_pointer( m_parent != 0 ? m_parent : MainFrame_getWindow(), false );
1252 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_move_focusOut );
1255 unsigned int Zoom_buttons(){
1256 return RAD_RBUTTON | RAD_ALT;
1261 void XYWnd_zoomDelta( int x, int y, unsigned int state, void* data ){
1264 while ( abs( g_dragZoom ) > 8 )
1266 if ( g_dragZoom > 0 ) {
1267 reinterpret_cast<XYWnd*>( data )->ZoomOut();
1272 reinterpret_cast<XYWnd*>( data )->ZoomIn();
1279 gboolean XYWnd_Zoom_focusOut( GtkWidget* widget, GdkEventFocus* event, XYWnd* xywnd ){
1284 void XYWnd::Zoom_Begin(){
1285 if ( m_zoom_started ) {
1288 m_zoom_started = true;
1290 g_xywnd_freezePointer.freeze_pointer( m_parent != 0 ? m_parent : MainFrame_getWindow(), m_gl_widget, XYWnd_zoomDelta, this );
1291 m_zoom_focusOut = g_signal_connect( G_OBJECT( m_gl_widget ), "focus_out_event", G_CALLBACK( XYWnd_Zoom_focusOut ), this );
1294 void XYWnd::Zoom_End(){
1295 m_zoom_started = false;
1296 g_xywnd_freezePointer.unfreeze_pointer( m_parent != 0 ? m_parent : MainFrame_getWindow(), false );
1297 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_zoom_focusOut );
1300 // makes sure the selected brush or camera is in view
1301 void XYWnd::PositionView( const Vector3& position ){
1302 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1303 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1305 m_vOrigin[nDim1] = position[nDim1];
1306 m_vOrigin[nDim2] = position[nDim2];
1310 XYWnd_Update( *this );
1313 void XYWnd::SetViewType( VIEWTYPE viewType ){
1314 m_viewType = viewType;
1317 if ( m_parent != 0 ) {
1318 gtk_window_set_title( m_parent, ViewType_getTitle( m_viewType ) );
1323 inline WindowVector WindowVector_forInteger( int x, int y ){
1324 return WindowVector( static_cast<float>( x ), static_cast<float>( y ) );
1327 void XYWnd::mouseDown( const WindowVector& position, ButtonIdentifier button, ModifierFlags modifiers ){
1328 XY_MouseDown( static_cast<int>( position.x() ), static_cast<int>( position.y() ), buttons_for_button_and_modifiers( button, modifiers ) );
1330 void XYWnd::XY_MouseDown( int x, int y, unsigned int buttons ){
1331 if ( buttons == Move_buttons() ) {
1333 EntityCreate_MouseDown( x, y );
1335 else if ( buttons == Zoom_buttons() ) {
1338 else if ( ClipMode() && ( buttons == Clipper_buttons() || buttons == Clipper_quick_buttons() ) ) {
1339 Clipper_OnLButtonDown( x, y );
1341 else if ( !ClipMode() && buttons == Clipper_quick_buttons() ) {
1343 g_quick_clipper = true;
1344 Clipper_OnLButtonDown( x, y );
1346 else if ( buttons == NewBrushDrag_buttons() && GlobalSelectionSystem().countSelected() == 0 ) {
1347 NewBrushDrag_Begin( x, y );
1349 // control mbutton = move camera
1350 else if ( buttons == MoveCamera_buttons() ) {
1351 XYWnd_PositionCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1353 // mbutton = angle camera
1354 else if ( buttons == OrientCamera_buttons() ) {
1355 XYWnd_OrientCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1357 else if ( buttons == SetCustomPivotOrigin_buttons() ) {
1358 SetCustomPivotOrigin( x, y );
1362 m_window_observer->onMouseDown( WindowVector_forInteger( x, y ), button_for_flags( buttons ), modifiers_for_flags( buttons ) );
1366 void XYWnd::XY_MouseUp( int x, int y, unsigned int buttons ){
1367 if ( m_move_started ) {
1369 EntityCreate_MouseUp( x, y );
1371 else if ( m_zoom_started ) {
1374 else if ( ClipMode() && ( buttons == Clipper_buttons() || buttons == Clipper_quick_buttons() ) ) {
1375 Clipper_OnLButtonUp( x, y );
1377 else if ( m_bNewBrushDrag ) {
1378 m_bNewBrushDrag = false;
1379 NewBrushDrag_End( x, y );
1380 if ( m_NewBrushDrag == 0 ) {
1381 //L button w/o created brush = tunnel selection
1382 m_window_observer->onMouseUp( WindowVector_forInteger( x, y ), button_for_flags( buttons ), modifiers_for_flags( buttons ) );
1387 m_window_observer->onMouseUp( WindowVector_forInteger( x, y ), button_for_flags( buttons ), modifiers_for_flags( buttons ) );
1391 void XYWnd::XY_MouseMoved( int x, int y, unsigned int buttons ){
1392 // rbutton = drag xy origin
1393 if ( m_move_started ) {
1396 else if ( m_zoom_started ) {
1399 else if ( ClipMode() && g_pMovingClip != 0 ) {
1400 Clipper_OnMouseMoved( x, y );
1402 // lbutton without selection = drag new brush
1403 else if ( m_bNewBrushDrag ) {
1404 NewBrushDrag( x, y );
1407 // control mbutton = move camera
1408 else if ( getButtonState() == MoveCamera_buttons() ) {
1409 XYWnd_PositionCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1412 // mbutton = angle camera
1413 else if ( getButtonState() == OrientCamera_buttons() ) {
1414 XYWnd_OrientCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1417 else if ( buttons == SetCustomPivotOrigin_buttons() ) {
1418 SetCustomPivotOrigin( x, y );
1423 m_window_observer->onMouseMotion( WindowVector_forInteger( x, y ), modifiers_for_flags( buttons ) );
1425 m_mousePosition[0] = m_mousePosition[1] = m_mousePosition[2] = 0.0;
1426 XY_ToPoint( x, y, m_mousePosition );
1427 XY_SnapToGrid( m_mousePosition );
1429 StringOutputStream status( 64 );
1430 status << "x:: " << FloatFormat( m_mousePosition[0], 6, 1 )
1431 << " y:: " << FloatFormat( m_mousePosition[1], 6, 1 )
1432 << " z:: " << FloatFormat( m_mousePosition[2], 6, 1 );
1433 g_pParentWnd->SetStatusText( g_pParentWnd->m_position_status, status.c_str() );
1435 if ( g_bCrossHairs ) {
1436 XYWnd_Update( *this );
1439 Clipper_Crosshair_OnMouseMoved( x, y );
1443 void XYWnd::EntityCreate_MouseDown( int x, int y ){
1444 m_entityCreate = true;
1445 m_entityCreate_x = x;
1446 m_entityCreate_y = y;
1449 void XYWnd::EntityCreate_MouseMove( int x, int y ){
1450 if ( m_entityCreate && ( m_entityCreate_x != x || m_entityCreate_y != y ) ) {
1451 m_entityCreate = false;
1455 void XYWnd::EntityCreate_MouseUp( int x, int y ){
1456 if ( m_entityCreate ) {
1457 m_entityCreate = false;
1462 inline float screen_normalised( int pos, unsigned int size ){
1463 return ( ( 2.0f * pos ) / size ) - 1.0f;
1466 inline float normalised_to_world( float normalised, float world_origin, float normalised2world_scale ){
1467 return world_origin + normalised * normalised2world_scale;
1471 // TTimo: watch it, this doesn't init one of the 3 coords
1472 void XYWnd::XY_ToPoint( int x, int y, Vector3& point ){
1473 float normalised2world_scale_x = m_nWidth / 2 / m_fScale;
1474 float normalised2world_scale_y = m_nHeight / 2 / m_fScale;
1475 if ( m_viewType == XY ) {
1476 point[0] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[0], normalised2world_scale_x );
1477 point[1] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[1], normalised2world_scale_y );
1479 else if ( m_viewType == YZ ) {
1480 point[1] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[1], normalised2world_scale_x );
1481 point[2] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[2], normalised2world_scale_y );
1485 point[0] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[0], normalised2world_scale_x );
1486 point[2] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[2], normalised2world_scale_y );
1490 void XYWnd::XY_SnapToGrid( Vector3& point ){
1491 if ( m_viewType == XY ) {
1492 point[0] = float_snapped( point[0], GetSnapGridSize() );
1493 point[1] = float_snapped( point[1], GetSnapGridSize() );
1495 else if ( m_viewType == YZ ) {
1496 point[1] = float_snapped( point[1], GetSnapGridSize() );
1497 point[2] = float_snapped( point[2], GetSnapGridSize() );
1501 point[0] = float_snapped( point[0], GetSnapGridSize() );
1502 point[2] = float_snapped( point[2], GetSnapGridSize() );
1506 void XYWnd::XY_LoadBackgroundImage( const char *name ){
1507 const char* relative = path_make_relative( name, GlobalFileSystem().findRoot( name ) );
1508 if ( relative == name ) {
1509 globalOutputStream() << "WARNING: could not extract the relative path, using full path instead\n";
1512 char fileNameWithoutExt[512];
1513 strncpy( fileNameWithoutExt, relative, sizeof( fileNameWithoutExt ) - 1 );
1514 fileNameWithoutExt[512 - 1] = '\0';
1515 fileNameWithoutExt[strlen( fileNameWithoutExt ) - 4] = '\0';
1517 Image *image = QERApp_LoadImage( 0, fileNameWithoutExt );
1519 globalOutputStream() << "Could not load texture " << fileNameWithoutExt << "\n";
1522 g_pParentWnd->ActiveXY()->m_tex = (qtexture_t*)malloc( sizeof( qtexture_t ) );
1523 LoadTextureRGBA( g_pParentWnd->ActiveXY()->XYWnd::m_tex, image->getRGBAPixels(), image->getWidth(), image->getHeight() );
1524 globalOutputStream() << "Loaded background texture " << relative << "\n";
1525 g_pParentWnd->ActiveXY()->m_backgroundActivated = true;
1528 switch ( g_pParentWnd->ActiveXY()->m_viewType )
1545 Select_GetBounds( min, max );
1546 g_pParentWnd->ActiveXY()->m_xmin = min[m_ix];
1547 g_pParentWnd->ActiveXY()->m_ymin = min[m_iy];
1548 g_pParentWnd->ActiveXY()->m_xmax = max[m_ix];
1549 g_pParentWnd->ActiveXY()->m_ymax = max[m_iy];
1552 void XYWnd::XY_DisableBackground( void ){
1553 g_pParentWnd->ActiveXY()->m_backgroundActivated = false;
1554 if ( g_pParentWnd->ActiveXY()->m_tex ) {
1555 free( g_pParentWnd->ActiveXY()->m_tex );
1557 g_pParentWnd->ActiveXY()->m_tex = NULL;
1560 void WXY_BackgroundSelect( void ){
1561 bool brushesSelected = Scene_countSelectedBrushes( GlobalSceneGraph() ) != 0;
1562 if ( !brushesSelected ) {
1563 gtk_MessageBox( 0, "You have to select some brushes to get the bounding box for.\n",
1564 "No selection", eMB_OK, eMB_ICONERROR );
1568 const char *filename = file_dialog( GTK_WIDGET( MainFrame_getWindow() ), TRUE, "Background Image", NULL, NULL );
1569 g_pParentWnd->ActiveXY()->XY_DisableBackground();
1571 g_pParentWnd->ActiveXY()->XY_LoadBackgroundImage( filename );
1576 ============================================================================
1580 ============================================================================
1589 double two_to_the_power( int power ){
1590 return pow( 2.0f, power );
1593 void XYWnd::XY_DrawAxis( void ){
1594 if ( g_xywindow_globals_private.show_axis ) {
1595 const char g_AxisName[3] = { 'X', 'Y', 'Z' };
1596 const int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1597 const int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1598 const int w = ( m_nWidth / 2 / m_fScale );
1599 const int h = ( m_nHeight / 2 / m_fScale );
1601 Vector3 colourX = ( m_viewType == YZ ) ? g_xywindow_globals.AxisColorY : g_xywindow_globals.AxisColorX;
1602 Vector3 colourY = ( m_viewType == XY ) ? g_xywindow_globals.AxisColorY : g_xywindow_globals.AxisColorZ;
1604 float grayX = vector3_dot( colourX, Vector3( 0.2989, 0.5870, 0.1140 ) );
1605 float grayY = vector3_dot( colourY, Vector3( 0.2989, 0.5870, 0.1140 ) );
1606 colourX[0] = colourX[1] = colourX[2] = grayX;
1607 colourY[0] = colourY[1] = colourY[2] = grayY;
1610 // draw two lines with corresponding axis colors to highlight current view
1611 // horizontal line: nDim1 color
1613 glBegin( GL_LINES );
1614 glColor3fv( vector3_to_array( colourX ) );
1615 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1616 glVertex2f( m_vOrigin[nDim1] - w + 65 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1618 glVertex2f( 32 / m_fScale, 0 );
1619 glColor3fv( vector3_to_array( colourY ) );
1620 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1621 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 20 / m_fScale );
1623 glVertex2f( 0, 32 / m_fScale );
1626 // now print axis symbols
1627 glColor3fv( vector3_to_array( colourX ) );
1628 glRasterPos2f( m_vOrigin[nDim1] - w + 55 / m_fScale, m_vOrigin[nDim2] + h - 55 / m_fScale );
1629 GlobalOpenGL().drawChar( g_AxisName[nDim1] );
1630 glRasterPos2f( 28 / m_fScale, -10 / m_fScale );
1631 GlobalOpenGL().drawChar( g_AxisName[nDim1] );
1632 glColor3fv( vector3_to_array( colourY ) );
1633 glRasterPos2f( m_vOrigin[nDim1] - w + 25 / m_fScale, m_vOrigin[nDim2] + h - 30 / m_fScale );
1634 GlobalOpenGL().drawChar( g_AxisName[nDim2] );
1635 glRasterPos2f( -10 / m_fScale, 28 / m_fScale );
1636 GlobalOpenGL().drawChar( g_AxisName[nDim2] );
1640 void XYWnd::RenderActive( void ){
1641 if ( glwidget_make_current( m_gl_widget ) != FALSE ) {
1642 if ( Map_Valid( g_map ) && ScreenUpdates_Enabled() ) {
1643 GlobalOpenGL_debugAssertNoErrors();
1644 glDrawBuffer( GL_FRONT );
1646 if ( g_xywindow_globals_private.show_outline ) {
1647 glMatrixMode( GL_PROJECTION );
1649 glOrtho( 0, m_nWidth, 0, m_nHeight, 0, 1 );
1651 glMatrixMode( GL_MODELVIEW );
1654 if( !Active() ){ //sorta erase
1655 glColor3fv( vector3_to_array( g_xywindow_globals.color_gridmajor ) );
1657 // four view mode doesn't colorize
1658 else if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) {
1659 glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) );
1663 switch ( m_viewType )
1666 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorX ) );
1669 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorY ) );
1672 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorZ ) );
1676 glBegin( GL_LINE_LOOP );
1677 glVertex2f( 0.5, 0.5 );
1678 glVertex2f( m_nWidth - 0.5, 1 );
1679 glVertex2f( m_nWidth - 0.5, m_nHeight - 0.5 );
1680 glVertex2f( 0.5, m_nHeight - 0.5 );
1683 // we do this part (the old way) only if show_axis is disabled
1684 if ( !g_xywindow_globals_private.show_axis ) {
1685 glMatrixMode( GL_PROJECTION );
1687 glOrtho( 0, m_nWidth, 0, m_nHeight, 0, 1 );
1689 glMatrixMode( GL_MODELVIEW );
1693 glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) );
1696 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridtext, 1.0f ) ) );
1699 glDisable( GL_BLEND );
1700 glRasterPos2f( 35, m_nHeight - 20 );
1702 GlobalOpenGL().drawString( ViewType_getTitle( m_viewType ) );
1706 glViewport( 0, 0, m_nWidth, m_nHeight );
1708 glMatrixMode( GL_PROJECTION );
1709 glLoadMatrixf( reinterpret_cast<const float*>( &m_projection ) );
1711 glMatrixMode( GL_MODELVIEW );
1713 glScalef( m_fScale, m_fScale, 1 );
1714 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1715 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1716 glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 );
1718 glDisable( GL_LINE_STIPPLE );
1719 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
1720 glDisableClientState( GL_NORMAL_ARRAY );
1721 glDisableClientState( GL_COLOR_ARRAY );
1722 glDisable( GL_TEXTURE_2D );
1723 glDisable( GL_LIGHTING );
1724 glDisable( GL_COLOR_MATERIAL );
1725 glDisable( GL_DEPTH_TEST );
1726 glDisable( GL_TEXTURE_1D );
1727 glDisable( GL_BLEND );
1729 XYWnd::XY_DrawAxis();
1732 glDrawBuffer( GL_BACK );
1733 GlobalOpenGL_debugAssertNoErrors();
1734 glwidget_make_current( m_gl_widget );
1739 void XYWnd::XY_DrawBackground( void ){
1740 glPushAttrib( GL_ALL_ATTRIB_BITS );
1742 glEnable( GL_TEXTURE_2D );
1743 glEnable( GL_BLEND );
1744 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
1745 glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1746 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
1747 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
1749 glPolygonMode( GL_FRONT, GL_FILL );
1751 glBindTexture( GL_TEXTURE_2D, m_tex->texture_number );
1752 glBegin( GL_QUADS );
1754 glColor4f( 1.0, 1.0, 1.0, m_alpha );
1755 glTexCoord2f( 0.0, 1.0 );
1756 glVertex2f( m_xmin, m_ymin );
1758 glTexCoord2f( 1.0, 1.0 );
1759 glVertex2f( m_xmax, m_ymin );
1761 glTexCoord2f( 1.0, 0.0 );
1762 glVertex2f( m_xmax, m_ymax );
1764 glTexCoord2f( 0.0, 0.0 );
1765 glVertex2f( m_xmin, m_ymax );
1768 glBindTexture( GL_TEXTURE_2D, 0 );
1773 void XYWnd::XY_DrawGrid( void ) {
1774 float x, y, xb, xe, yb, ye;
1777 float step, minor_step, stepx, stepy;
1778 step = minor_step = stepx = stepy = GetGridSize();
1780 int minor_power = Grid_getPower();
1783 while ( ( minor_step * m_fScale ) <= 4.0f ) { // make sure minor grid spacing is at least 4 pixels on the screen
1787 int power = minor_power;
1788 while ( ( power % 3 ) != 0 || ( step * m_fScale ) <= 32.0f ) { // make sure major grid spacing is at least 32 pixels on the screen
1790 step = float(two_to_the_power( power ) );
1792 mask = ( 1 << ( power - minor_power ) ) - 1;
1793 while ( ( stepx * m_fScale ) <= 32.0f ) // text step x must be at least 32
1795 while ( ( stepy * m_fScale ) <= 32.0f ) // text step y must be at least 32
1798 a = ( ( GetSnapGridSize() > 0.0f ) ? 1.0f : 0.3f );
1800 glDisable( GL_TEXTURE_2D );
1801 glDisable( GL_TEXTURE_1D );
1802 glDisable( GL_DEPTH_TEST );
1803 glDisable( GL_BLEND );
1806 w = ( m_nWidth / 2 / m_fScale );
1807 h = ( m_nHeight / 2 / m_fScale );
1809 const int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1810 const int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1812 xb = m_vOrigin[nDim1] - w;
1813 if ( xb < region_mins[nDim1] ) {
1814 xb = region_mins[nDim1];
1816 xb = step * floor( xb / step );
1818 xe = m_vOrigin[nDim1] + w;
1819 if ( xe > region_maxs[nDim1] ) {
1820 xe = region_maxs[nDim1];
1822 xe = step * ceil( xe / step );
1824 yb = m_vOrigin[nDim2] - h;
1825 if ( yb < region_mins[nDim2] ) {
1826 yb = region_mins[nDim2];
1828 yb = step * floor( yb / step );
1830 ye = m_vOrigin[nDim2] + h;
1831 if ( ye > region_maxs[nDim2] ) {
1832 ye = region_maxs[nDim2];
1834 ye = step * ceil( ye / step );
1836 #define COLORS_DIFFER( a,b ) \
1837 ( ( a )[0] != ( b )[0] || \
1838 ( a )[1] != ( b )[1] || \
1839 ( a )[2] != ( b )[2] )
1842 // draw minor blocks
1843 if ( g_xywindow_globals_private.d_showgrid || a < 1.0f ) {
1845 glEnable( GL_BLEND );
1848 if ( COLORS_DIFFER( g_xywindow_globals.color_gridminor, g_xywindow_globals.color_gridback ) ) {
1849 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridminor, a ) ) );
1851 glBegin( GL_LINES );
1853 for ( x = xb ; x < xe ; x += minor_step, ++i ) {
1854 if ( ( i & mask ) != 0 ) {
1855 glVertex2f( x, yb );
1856 glVertex2f( x, ye );
1860 for ( y = yb ; y < ye ; y += minor_step, ++i ) {
1861 if ( ( i & mask ) != 0 ) {
1862 glVertex2f( xb, y );
1863 glVertex2f( xe, y );
1869 // draw major blocks
1870 if ( COLORS_DIFFER( g_xywindow_globals.color_gridmajor, g_xywindow_globals.color_gridminor ) ) {
1871 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridmajor, a ) ) );
1873 glBegin( GL_LINES );
1874 for ( x = xb ; x <= xe ; x += step ) {
1875 glVertex2f( x, yb );
1876 glVertex2f( x, ye );
1878 for ( y = yb ; y <= ye ; y += step ) {
1879 glVertex2f( xb, y );
1880 glVertex2f( xe, y );
1886 glDisable( GL_BLEND );
1890 // draw coordinate text if needed
1891 if ( g_xywindow_globals_private.show_coordinates ) {
1892 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridtext, 1.0f ) ) );
1893 float offx = m_vOrigin[nDim2] + h - ( 4 + GlobalOpenGL().m_font->getPixelAscent() ) / m_fScale;
1894 float offy = m_vOrigin[nDim1] - w + 4 / m_fScale;
1895 for ( x = xb - fmod( xb, stepx ); x <= xe ; x += stepx ) {
1896 glRasterPos2f( x, offx );
1897 sprintf( text, "%g", x );
1898 GlobalOpenGL().drawString( text );
1900 for ( y = yb - fmod( yb, stepy ); y <= ye ; y += stepy ) {
1901 glRasterPos2f( offy, y );
1902 sprintf( text, "%g", y );
1903 GlobalOpenGL().drawString( text );
1907 // we do this part (the old way) only if show_axis is disabled
1908 if ( !g_xywindow_globals_private.show_axis ) {
1910 glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) );
1913 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridtext, 1.0f ) ) );
1916 glRasterPos2f( m_vOrigin[nDim1] - w + 35 / m_fScale, m_vOrigin[nDim2] + h - 20 / m_fScale );
1918 GlobalOpenGL().drawString( ViewType_getTitle( m_viewType ) );
1921 XYWnd::XY_DrawAxis();
1923 // show current work zone?
1924 // the work zone is used to place dropped points and brushes
1925 if ( g_xywindow_globals_private.d_show_work ) {
1926 glColor4f( 1.0f, 0.0f, 0.0f, 1.0f );
1927 glBegin( GL_LINES );
1928 glVertex2f( xb, Select_getWorkZone().d_work_min[nDim2] );
1929 glVertex2f( xe, Select_getWorkZone().d_work_min[nDim2] );
1930 glVertex2f( xb, Select_getWorkZone().d_work_max[nDim2] );
1931 glVertex2f( xe, Select_getWorkZone().d_work_max[nDim2] );
1932 glVertex2f( Select_getWorkZone().d_work_min[nDim1], yb );
1933 glVertex2f( Select_getWorkZone().d_work_min[nDim1], ye );
1934 glVertex2f( Select_getWorkZone().d_work_max[nDim1], yb );
1935 glVertex2f( Select_getWorkZone().d_work_max[nDim1], ye );
1945 void XYWnd::XY_DrawBlockGrid(){
1946 if ( Map_FindWorldspawn( g_map ) == 0 ) {
1949 const char *value = Node_getEntity( *Map_GetWorldspawn( g_map ) )->getKeyValue( "_blocksize" );
1950 if ( strlen( value ) ) {
1951 sscanf( value, "%i", &g_xywindow_globals_private.blockSize );
1954 if ( !g_xywindow_globals_private.blockSize || g_xywindow_globals_private.blockSize > 65536 || g_xywindow_globals_private.blockSize < 1024 ) {
1955 // don't use custom blocksize if it is less than the default, or greater than the maximum world coordinate
1956 g_xywindow_globals_private.blockSize = 1024;
1959 float x, y, xb, xe, yb, ye;
1963 glDisable( GL_TEXTURE_2D );
1964 glDisable( GL_TEXTURE_1D );
1965 glDisable( GL_DEPTH_TEST );
1966 glDisable( GL_BLEND );
1968 w = ( m_nWidth / 2 / m_fScale );
1969 h = ( m_nHeight / 2 / m_fScale );
1971 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1972 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1974 xb = m_vOrigin[nDim1] - w;
1975 if ( xb < region_mins[nDim1] ) {
1976 xb = region_mins[nDim1];
1978 xb = static_cast<float>( g_xywindow_globals_private.blockSize * floor( xb / g_xywindow_globals_private.blockSize ) );
1980 xe = m_vOrigin[nDim1] + w;
1981 if ( xe > region_maxs[nDim1] ) {
1982 xe = region_maxs[nDim1];
1984 xe = static_cast<float>( g_xywindow_globals_private.blockSize * ceil( xe / g_xywindow_globals_private.blockSize ) );
1986 yb = m_vOrigin[nDim2] - h;
1987 if ( yb < region_mins[nDim2] ) {
1988 yb = region_mins[nDim2];
1990 yb = static_cast<float>( g_xywindow_globals_private.blockSize * floor( yb / g_xywindow_globals_private.blockSize ) );
1992 ye = m_vOrigin[nDim2] + h;
1993 if ( ye > region_maxs[nDim2] ) {
1994 ye = region_maxs[nDim2];
1996 ye = static_cast<float>( g_xywindow_globals_private.blockSize * ceil( ye / g_xywindow_globals_private.blockSize ) );
1998 // draw major blocks
2000 glColor3fv( vector3_to_array( g_xywindow_globals.color_gridblock ) );
2003 glBegin( GL_LINES );
2005 for ( x = xb ; x <= xe ; x += g_xywindow_globals_private.blockSize )
2007 glVertex2f( x, yb );
2008 glVertex2f( x, ye );
2011 if ( m_viewType == XY ) {
2012 for ( y = yb ; y <= ye ; y += g_xywindow_globals_private.blockSize )
2014 glVertex2f( xb, y );
2015 glVertex2f( xe, y );
2022 // draw coordinate text if needed
2024 if ( m_viewType == XY && m_fScale > .1 ) {
2025 for ( x = xb ; x < xe ; x += g_xywindow_globals_private.blockSize )
2026 for ( y = yb ; y < ye ; y += g_xywindow_globals_private.blockSize )
2028 glRasterPos2f( x + ( g_xywindow_globals_private.blockSize / 2 ), y + ( g_xywindow_globals_private.blockSize / 2 ) );
2029 sprintf( text, "%i,%i",(int)floor( x / g_xywindow_globals_private.blockSize ), (int)floor( y / g_xywindow_globals_private.blockSize ) );
2030 GlobalOpenGL().drawString( text );
2034 glColor4f( 0, 0, 0, 0 );
2037 void XYWnd::DrawCameraIcon( const Vector3& origin, const Vector3& angles ){
2038 Cam.fov = 48 / m_fScale;
2039 Cam.box = 16 / m_fScale;
2041 if ( m_viewType == XY ) {
2044 Cam.a = degrees_to_radians( angles[CAMERA_YAW] );
2046 else if ( m_viewType == YZ ) {
2049 Cam.a = degrees_to_radians( angles[CAMERA_PITCH] );
2055 Cam.a = degrees_to_radians( angles[CAMERA_PITCH] );
2058 //glColor3f( 0.0, 0.0, 1.0 );
2059 glColor3f( 1.0, 1.0, 1.0 );
2060 glBegin( GL_LINE_STRIP );
2061 glVertex3f( Cam.x - Cam.box,Cam.y,0 );
2062 glVertex3f( Cam.x,Cam.y + ( Cam.box / 2 ),0 );
2063 glVertex3f( Cam.x + Cam.box,Cam.y,0 );
2064 glVertex3f( Cam.x,Cam.y - ( Cam.box / 2 ),0 );
2065 glVertex3f( Cam.x - Cam.box,Cam.y,0 );
2066 glVertex3f( Cam.x + Cam.box,Cam.y,0 );
2069 glBegin( GL_LINE_STRIP );
2070 glVertex3f( Cam.x + static_cast<float>( Cam.fov * cos( Cam.a + c_pi / 4 ) ), Cam.y + static_cast<float>( Cam.fov * sin( Cam.a + c_pi / 4 ) ), 0 );
2071 glVertex3f( Cam.x, Cam.y, 0 );
2072 glVertex3f( Cam.x + static_cast<float>( Cam.fov * cos( Cam.a - c_pi / 4 ) ), Cam.y + static_cast<float>( Cam.fov * sin( Cam.a - c_pi / 4 ) ), 0 );
2077 void XYWnd::UpdateCameraIcon( void ){
2078 if ( glwidget_make_current( m_gl_widget ) != FALSE ) {
2079 if ( Map_Valid( g_map ) && ScreenUpdates_Enabled() ) {
2080 GlobalOpenGL_debugAssertNoErrors();
2081 glDrawBuffer( GL_FRONT );
2084 glViewport( 0, 0, m_nWidth, m_nHeight );
2086 glMatrixMode( GL_PROJECTION );
2087 glLoadMatrixf( reinterpret_cast<const float*>( &m_projection ) );
2089 glMatrixMode( GL_MODELVIEW );
2091 glScalef( m_fScale, m_fScale, 1 );
2092 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
2093 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
2094 glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 );
2096 glDisable( GL_LINE_STIPPLE );
2097 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2098 glDisableClientState( GL_NORMAL_ARRAY );
2099 glDisableClientState( GL_COLOR_ARRAY );
2100 glDisable( GL_TEXTURE_2D );
2101 glDisable( GL_LIGHTING );
2102 glDisable( GL_COLOR_MATERIAL );
2103 glDisable( GL_DEPTH_TEST );
2104 glDisable( GL_TEXTURE_1D );
2106 glEnable( GL_BLEND );
2107 glBlendFunc( GL_ONE_MINUS_DST_COLOR, GL_ZERO );
2109 //glColor3f( 0.0, 0.0, 1.0 );
2110 glColor3f( 1.0, 1.0, 1.0 );
2111 glBegin( GL_LINE_STRIP );
2112 glVertex3f( Cam.x - Cam.box,Cam.y,0 );
2113 glVertex3f( Cam.x,Cam.y + ( Cam.box / 2 ),0 );
2114 glVertex3f( Cam.x + Cam.box,Cam.y,0 );
2115 glVertex3f( Cam.x,Cam.y - ( Cam.box / 2 ),0 );
2116 glVertex3f( Cam.x - Cam.box,Cam.y,0 );
2117 glVertex3f( Cam.x + Cam.box,Cam.y,0 );
2120 glBegin( GL_LINE_STRIP );
2121 glVertex3f( Cam.x + static_cast<float>( Cam.fov * cos( Cam.a + c_pi / 4 ) ), Cam.y + static_cast<float>( Cam.fov * sin( Cam.a + c_pi / 4 ) ), 0 );
2122 glVertex3f( Cam.x, Cam.y, 0 );
2123 glVertex3f( Cam.x + static_cast<float>( Cam.fov * cos( Cam.a - c_pi / 4 ) ), Cam.y + static_cast<float>( Cam.fov * sin( Cam.a - c_pi / 4 ) ), 0 );
2126 XYWnd::DrawCameraIcon( Camera_getOrigin( *g_pParentWnd->GetCamWnd() ), Camera_getAngles( *g_pParentWnd->GetCamWnd() ) );
2128 glDisable( GL_BLEND );
2131 glDrawBuffer( GL_BACK );
2132 GlobalOpenGL_debugAssertNoErrors();
2133 glwidget_make_current( m_gl_widget );
2139 float Betwixt( float f1, float f2 ){
2141 return f2 + ( ( f1 - f2 ) / 2 );
2144 return f1 + ( ( f2 - f1 ) / 2 );
2149 // can be greatly simplified but per usual i am in a hurry
2150 // which is not an excuse, just a fact
2151 void XYWnd::PaintSizeInfo( int nDim1, int nDim2, Vector3& vMinBounds, Vector3& vMaxBounds ){
2152 if ( vector3_equal( vMinBounds, vMaxBounds ) ) {
2155 const char* g_pDimStrings[] = {"x:", "y:", "z:"};
2156 typedef const char* OrgStrings[2];
2157 const OrgStrings g_pOrgStrings[] = { { "x:", "y:", }, { "x:", "z:", }, { "y:", "z:", } };
2159 Vector3 vSize( vector3_subtracted( vMaxBounds, vMinBounds ) );
2161 glColor3f( g_xywindow_globals.color_selbrushes[0] * .65f,
2162 g_xywindow_globals.color_selbrushes[1] * .65f,
2163 g_xywindow_globals.color_selbrushes[2] * .65f );
2165 StringOutputStream dimensions( 16 );
2167 if ( m_viewType == XY ) {
2168 glBegin( GL_LINES );
2170 glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f );
2171 glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
2173 glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
2174 glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
2176 glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f );
2177 glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
2180 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2], 0.0f );
2181 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f );
2183 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f );
2184 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f );
2186 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2], 0.0f );
2187 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f );
2191 glRasterPos3f( Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), vMinBounds[nDim2] - 20.0f / m_fScale, 0.0f );
2192 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
2193 GlobalOpenGL().drawString( dimensions.c_str() );
2196 glRasterPos3f( vMaxBounds[nDim1] + 16.0f / m_fScale, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ), 0.0f );
2197 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
2198 GlobalOpenGL().drawString( dimensions.c_str() );
2201 glRasterPos3f( vMinBounds[nDim1] + 4, vMaxBounds[nDim2] + 8 / m_fScale, 0.0f );
2202 dimensions << "(" << g_pOrgStrings[0][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[0][1] << vMaxBounds[nDim2] << ")";
2203 GlobalOpenGL().drawString( dimensions.c_str() );
2205 else if ( m_viewType == XZ ) {
2206 glBegin( GL_LINES );
2208 glVertex3f( vMinBounds[nDim1], 0, vMinBounds[nDim2] - 6.0f / m_fScale );
2209 glVertex3f( vMinBounds[nDim1], 0, vMinBounds[nDim2] - 10.0f / m_fScale );
2211 glVertex3f( vMinBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale );
2212 glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale );
2214 glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 6.0f / m_fScale );
2215 glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale );
2218 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, 0,vMinBounds[nDim2] );
2219 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMinBounds[nDim2] );
2221 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMinBounds[nDim2] );
2222 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMaxBounds[nDim2] );
2224 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, 0,vMaxBounds[nDim2] );
2225 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMaxBounds[nDim2] );
2229 glRasterPos3f( Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), 0, vMinBounds[nDim2] - 20.0f / m_fScale );
2230 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
2231 GlobalOpenGL().drawString( dimensions.c_str() );
2234 glRasterPos3f( vMaxBounds[nDim1] + 16.0f / m_fScale, 0, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ) );
2235 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
2236 GlobalOpenGL().drawString( dimensions.c_str() );
2239 glRasterPos3f( vMinBounds[nDim1] + 4, 0, vMaxBounds[nDim2] + 8 / m_fScale );
2240 dimensions << "(" << g_pOrgStrings[1][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[1][1] << vMaxBounds[nDim2] << ")";
2241 GlobalOpenGL().drawString( dimensions.c_str() );
2245 glBegin( GL_LINES );
2247 glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale );
2248 glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2250 glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2251 glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2253 glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale );
2254 glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2257 glVertex3f( 0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2] );
2258 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2] );
2260 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2] );
2261 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2] );
2263 glVertex3f( 0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2] );
2264 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2] );
2268 glRasterPos3f( 0, Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), vMinBounds[nDim2] - 20.0f / m_fScale );
2269 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
2270 GlobalOpenGL().drawString( dimensions.c_str() );
2273 glRasterPos3f( 0, vMaxBounds[nDim1] + 16.0f / m_fScale, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ) );
2274 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
2275 GlobalOpenGL().drawString( dimensions.c_str() );
2278 glRasterPos3f( 0, vMinBounds[nDim1] + 4.0f, vMaxBounds[nDim2] + 8 / m_fScale );
2279 dimensions << "(" << g_pOrgStrings[2][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[2][1] << vMaxBounds[nDim2] << ")";
2280 GlobalOpenGL().drawString( dimensions.c_str() );
2284 class XYRenderer : public Renderer
2292 unsigned int m_highlight;
2296 XYRenderer( RenderStateFlags globalstate, Shader* selected ) :
2297 m_globalstate( globalstate ),
2298 m_state_selected( selected ){
2299 ASSERT_NOTNULL( selected );
2300 m_state_stack.push_back( state_type() );
2303 void SetState( Shader* state, EStyle style ){
2304 ASSERT_NOTNULL( state );
2305 if ( style == eWireframeOnly ) {
2306 m_state_stack.back().m_state = state;
2309 const EStyle getStyle() const {
2310 return eWireframeOnly;
2313 m_state_stack.push_back( m_state_stack.back() );
2316 ASSERT_MESSAGE( !m_state_stack.empty(), "popping empty stack" );
2317 m_state_stack.pop_back();
2319 void Highlight( EHighlightMode mode, bool bEnable = true ){
2321 ? m_state_stack.back().m_highlight |= mode
2322 : m_state_stack.back().m_highlight &= ~mode;
2324 void addRenderable( const OpenGLRenderable& renderable, const Matrix4& localToWorld ){
2325 if ( m_state_stack.back().m_highlight & ePrimitive ) {
2326 m_state_selected->addRenderable( renderable, localToWorld );
2330 m_state_stack.back().m_state->addRenderable( renderable, localToWorld );
2334 void render( const Matrix4& modelview, const Matrix4& projection ){
2335 GlobalShaderCache().render( m_globalstate, modelview, projection );
2338 std::vector<state_type> m_state_stack;
2339 RenderStateFlags m_globalstate;
2340 Shader* m_state_selected;
2343 void XYWnd::updateProjection(){
2344 m_projection[0] = 1.0f / static_cast<float>( m_nWidth / 2 );
2345 m_projection[5] = 1.0f / static_cast<float>( m_nHeight / 2 );
2346 m_projection[10] = 1.0f / ( g_MaxWorldCoord * m_fScale );
2348 m_projection[12] = 0.0f;
2349 m_projection[13] = 0.0f;
2350 m_projection[14] = -1.0f;
2362 m_projection[11] = 0.0f;
2364 m_projection[15] = 1.0f;
2366 m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight );
2369 // note: modelview matrix must have a uniform scale, otherwise strange things happen when rendering the rotation manipulator.
2370 void XYWnd::updateModelview(){
2371 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
2372 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
2375 m_modelview[12] = -m_vOrigin[nDim1] * m_fScale;
2376 m_modelview[13] = -m_vOrigin[nDim2] * m_fScale;
2377 m_modelview[14] = g_MaxWorldCoord * m_fScale;
2380 switch ( m_viewType )
2383 m_modelview[0] = m_fScale;
2388 m_modelview[5] = m_fScale;
2393 m_modelview[10] = -m_fScale;
2396 m_modelview[0] = m_fScale;
2402 m_modelview[6] = m_fScale;
2405 m_modelview[9] = m_fScale;
2406 m_modelview[10] = 0;
2411 m_modelview[2] = -m_fScale;
2413 m_modelview[4] = m_fScale;
2418 m_modelview[9] = m_fScale;
2419 m_modelview[10] = 0;
2423 m_modelview[3] = m_modelview[7] = m_modelview[11] = 0;
2424 m_modelview[15] = 1;
2426 m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight );
2435 //#define DBG_SCENEDUMP
2437 void XYWnd::XY_Draw(){
2441 glViewport( 0, 0, m_nWidth, m_nHeight );
2442 glClearColor( g_xywindow_globals.color_gridback[0],
2443 g_xywindow_globals.color_gridback[1],
2444 g_xywindow_globals.color_gridback[2],0 );
2446 glClear( GL_COLOR_BUFFER_BIT );
2452 glMatrixMode( GL_PROJECTION );
2453 glLoadMatrixf( reinterpret_cast<const float*>( &m_projection ) );
2455 glMatrixMode( GL_MODELVIEW );
2457 glScalef( m_fScale, m_fScale, 1 );
2458 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
2459 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
2460 glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 );
2462 glDisable( GL_LINE_STIPPLE );
2464 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2465 glDisableClientState( GL_NORMAL_ARRAY );
2466 glDisableClientState( GL_COLOR_ARRAY );
2467 glDisable( GL_TEXTURE_2D );
2468 glDisable( GL_LIGHTING );
2469 glDisable( GL_COLOR_MATERIAL );
2470 glDisable( GL_DEPTH_TEST );
2472 if ( m_backgroundActivated ) {
2473 XY_DrawBackground();
2477 if ( g_xywindow_globals_private.show_blocks ) {
2481 glLoadMatrixf( reinterpret_cast<const float*>( &m_modelview ) );
2483 unsigned int globalstate = RENDER_COLOURARRAY | RENDER_COLOURWRITE | RENDER_POLYGONSMOOTH | RENDER_LINESMOOTH;
2484 if ( !g_xywindow_globals.m_bNoStipple ) {
2485 globalstate |= RENDER_LINESTIPPLE;
2489 XYRenderer renderer( globalstate, m_state_selected );
2491 Scene_Render( renderer, m_view );
2493 GlobalOpenGL_debugAssertNoErrors();
2494 renderer.render( m_modelview, m_projection );
2495 GlobalOpenGL_debugAssertNoErrors();
2498 glDepthMask( GL_FALSE );
2500 GlobalOpenGL_debugAssertNoErrors();
2502 glLoadMatrixf( reinterpret_cast<const float*>( &m_modelview ) );
2504 GlobalOpenGL_debugAssertNoErrors();
2505 glDisable( GL_LINE_STIPPLE );
2506 GlobalOpenGL_debugAssertNoErrors();
2508 GlobalOpenGL_debugAssertNoErrors();
2509 if ( GlobalOpenGL().GL_1_3() ) {
2510 glActiveTexture( GL_TEXTURE0 );
2511 glClientActiveTexture( GL_TEXTURE0 );
2513 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2514 GlobalOpenGL_debugAssertNoErrors();
2515 glDisableClientState( GL_NORMAL_ARRAY );
2516 GlobalOpenGL_debugAssertNoErrors();
2517 glDisableClientState( GL_COLOR_ARRAY );
2518 GlobalOpenGL_debugAssertNoErrors();
2519 glDisable( GL_TEXTURE_2D );
2520 GlobalOpenGL_debugAssertNoErrors();
2521 glDisable( GL_LIGHTING );
2522 GlobalOpenGL_debugAssertNoErrors();
2523 glDisable( GL_COLOR_MATERIAL );
2524 GlobalOpenGL_debugAssertNoErrors();
2526 GlobalOpenGL_debugAssertNoErrors();
2530 if ( g_xywindow_globals_private.m_bSizePaint && GlobalSelectionSystem().countSelected() != 0 ) {
2532 Select_GetBounds( min, max );
2533 PaintSizeInfo( nDim1, nDim2, min, max );
2536 if ( g_bCrossHairs ) {
2537 glColor4f( 0.2f, 0.9f, 0.2f, 0.8f );
2538 glBegin( GL_LINES );
2539 if ( m_viewType == XY ) {
2540 glVertex2f( 2.0f * g_MinWorldCoord, m_mousePosition[1] );
2541 glVertex2f( 2.0f * g_MaxWorldCoord, m_mousePosition[1] );
2542 glVertex2f( m_mousePosition[0], 2.0f * g_MinWorldCoord );
2543 glVertex2f( m_mousePosition[0], 2.0f * g_MaxWorldCoord );
2545 else if ( m_viewType == YZ ) {
2546 glVertex3f( m_mousePosition[0], 2.0f * g_MinWorldCoord, m_mousePosition[2] );
2547 glVertex3f( m_mousePosition[0], 2.0f * g_MaxWorldCoord, m_mousePosition[2] );
2548 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MinWorldCoord );
2549 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MaxWorldCoord );
2553 glVertex3f( 2.0f * g_MinWorldCoord, m_mousePosition[1], m_mousePosition[2] );
2554 glVertex3f( 2.0f * g_MaxWorldCoord, m_mousePosition[1], m_mousePosition[2] );
2555 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MinWorldCoord );
2556 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MaxWorldCoord );
2562 GlobalClipPoints_Draw( m_fScale );
2565 GlobalOpenGL_debugAssertNoErrors();
2569 glScalef( m_fScale, m_fScale, 1 );
2570 glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 );
2572 glEnable( GL_BLEND );
2573 glBlendFunc( GL_ONE_MINUS_DST_COLOR, GL_ZERO );
2574 DrawCameraIcon( Camera_getOrigin( *g_pParentWnd->GetCamWnd() ), Camera_getAngles( *g_pParentWnd->GetCamWnd() ) );
2575 glDisable( GL_BLEND );
2577 Feedback_draw2D( m_viewType );
2579 if ( g_xywindow_globals_private.show_outline ) {
2581 glMatrixMode( GL_PROJECTION );
2583 glOrtho( 0, m_nWidth, 0, m_nHeight, 0, 1 );
2585 glMatrixMode( GL_MODELVIEW );
2588 // four view mode doesn't colorize
2589 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) {
2590 glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) );
2594 switch ( m_viewType )
2597 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorX ) );
2600 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorY ) );
2603 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorZ ) );
2607 glBegin( GL_LINE_LOOP );
2608 glVertex2f( 0.5, 0.5 );
2609 glVertex2f( m_nWidth - 0.5, 1 );
2610 glVertex2f( m_nWidth - 0.5, m_nHeight - 0.5 );
2611 glVertex2f( 0.5, m_nHeight - 0.5 );
2616 GlobalOpenGL_debugAssertNoErrors();
2621 void XYWnd_MouseToPoint( XYWnd* xywnd, int x, int y, Vector3& point ){
2622 xywnd->XY_ToPoint( x, y, point );
2623 xywnd->XY_SnapToGrid( point );
2625 int nDim = ( xywnd->GetViewType() == XY ) ? 2 : ( xywnd->GetViewType() == YZ ) ? 0 : 1;
2626 float fWorkMid = float_mid( Select_getWorkZone().d_work_min[nDim], Select_getWorkZone().d_work_max[nDim] );
2627 point[nDim] = float_snapped( fWorkMid, GetGridSize() );
2630 void XYWnd::OnEntityCreate( const char* item ){
2631 StringOutputStream command;
2632 command << "entityCreate -class " << item;
2633 UndoableCommand undo( command.c_str() );
2635 XYWnd_MouseToPoint( this, m_entityCreate_x, m_entityCreate_y, point );
2636 Entity_createFromSelection( item, point );
2641 void GetFocusPosition( Vector3& position ){
2642 if ( GlobalSelectionSystem().countSelected() != 0 ) {
2643 Select_GetMid( position );
2647 position = Camera_getOrigin( *g_pParentWnd->GetCamWnd() );
2651 void XYWnd_Focus( XYWnd* xywnd ){
2653 GetFocusPosition( position );
2654 xywnd->PositionView( position );
2657 void XY_Split_Focus(){
2659 GetFocusPosition( position );
2660 if ( g_pParentWnd->GetXYWnd() ) {
2661 g_pParentWnd->GetXYWnd()->PositionView( position );
2663 if ( g_pParentWnd->GetXZWnd() ) {
2664 g_pParentWnd->GetXZWnd()->PositionView( position );
2666 if ( g_pParentWnd->GetYZWnd() ) {
2667 g_pParentWnd->GetYZWnd()->PositionView( position );
2672 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) {
2673 // cannot do this in a split window
2674 // do something else that the user may want here
2679 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2680 XYWnd_Focus( xywnd );
2683 void XY_TopFrontSide( VIEWTYPE viewtype ){
2684 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) {
2685 // cannot do this in a split window
2686 // do something else that the user may want here
2690 XYWnd* xywnd = g_pParentWnd->CurrentStyle() == MainFrame::eFloating ? g_pParentWnd->ActiveXY() : g_pParentWnd->GetXYWnd();
2691 xywnd->SetViewType( viewtype );
2692 XYWnd_Focus( xywnd );
2696 XY_TopFrontSide( XY );
2700 XY_TopFrontSide( XZ );
2704 XY_TopFrontSide( YZ );
2707 void XY_NextView( XYWnd* xywnd ){
2708 if ( xywnd->GetViewType() == XY ) {
2709 xywnd->SetViewType( XZ );
2711 else if ( xywnd->GetViewType() == XZ ) {
2712 xywnd->SetViewType( YZ );
2715 xywnd->SetViewType( XY );
2717 XYWnd_Focus( xywnd );
2721 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) {
2722 // cannot do this in a split window
2723 // do something else that the user may want here
2727 XYWnd* xywnd = g_pParentWnd->CurrentStyle() == MainFrame::eFloating ? g_pParentWnd->ActiveXY() : g_pParentWnd->GetXYWnd();
2728 XY_NextView( xywnd );
2732 if ( g_pParentWnd->GetXYWnd() ) {
2733 g_pParentWnd->GetXYWnd()->SetScale( 1 );
2735 if ( g_pParentWnd->GetXZWnd() ) {
2736 g_pParentWnd->GetXZWnd()->SetScale( 1 );
2738 if ( g_pParentWnd->GetYZWnd() ) {
2739 g_pParentWnd->GetYZWnd()->SetScale( 1 );
2744 g_pParentWnd->ActiveXY()->ZoomIn();
2747 // NOTE: the zoom out factor is 4/5, we could think about customizing it
2748 // we don't go below a zoom factor corresponding to 10% of the max world size
2749 // (this has to be computed against the window size)
2751 g_pParentWnd->ActiveXY()->ZoomOut();
2756 ToggleShown g_xy_top_shown( true );
2758 void XY_Top_Shown_Construct( GtkWindow* parent ){
2759 g_xy_top_shown.connect( GTK_WIDGET( parent ) );
2762 ToggleShown g_yz_side_shown( false );
2764 void YZ_Side_Shown_Construct( GtkWindow* parent ){
2765 g_yz_side_shown.connect( GTK_WIDGET( parent ) );
2768 ToggleShown g_xz_front_shown( false );
2770 void XZ_Front_Shown_Construct( GtkWindow* parent ){
2771 g_xz_front_shown.connect( GTK_WIDGET( parent ) );
2775 class EntityClassMenu : public ModuleObserver
2777 std::size_t m_unrealised;
2779 EntityClassMenu() : m_unrealised( 1 ){
2782 if ( --m_unrealised == 0 ) {
2786 if ( ++m_unrealised == 1 ) {
2787 if ( XYWnd::m_mnuDrop != 0 ) {
2788 gtk_widget_destroy( GTK_WIDGET( XYWnd::m_mnuDrop ) );
2789 XYWnd::m_mnuDrop = 0;
2795 EntityClassMenu g_EntityClassMenu;
2800 void ShowNamesExport( const BoolImportCallback& importer ){
2801 importer( GlobalEntityCreator().getShowNames() );
2803 typedef FreeCaller1<const BoolImportCallback&, ShowNamesExport> ShowNamesExportCaller;
2804 ShowNamesExportCaller g_show_names_caller;
2805 ToggleItem g_show_names( g_show_names_caller );
2806 void ShowNamesToggle(){
2807 GlobalEntityCreator().setShowNames( !GlobalEntityCreator().getShowNames() );
2808 g_show_names.update();
2809 XY_UpdateAllWindows();
2812 void ShowAnglesExport( const BoolImportCallback& importer ){
2813 importer( GlobalEntityCreator().getShowAngles() );
2815 typedef FreeCaller1<const BoolImportCallback&, ShowAnglesExport> ShowAnglesExportCaller;
2816 ShowAnglesExportCaller g_show_angles_caller;
2817 ToggleItem g_show_angles( g_show_angles_caller );
2818 void ShowAnglesToggle(){
2819 GlobalEntityCreator().setShowAngles( !GlobalEntityCreator().getShowAngles() );
2820 g_show_angles.update();
2821 XY_UpdateAllWindows();
2824 BoolExportCaller g_show_blocks_caller( g_xywindow_globals_private.show_blocks );
2825 ToggleItem g_show_blocks( g_show_blocks_caller );
2826 void ShowBlocksToggle(){
2827 g_xywindow_globals_private.show_blocks ^= 1;
2828 g_show_blocks.update();
2829 XY_UpdateAllWindows();
2832 BoolExportCaller g_show_coordinates_caller( g_xywindow_globals_private.show_coordinates );
2833 ToggleItem g_show_coordinates( g_show_coordinates_caller );
2834 void ShowCoordinatesToggle(){
2835 g_xywindow_globals_private.show_coordinates ^= 1;
2836 g_show_coordinates.update();
2837 XY_UpdateAllWindows();
2840 BoolExportCaller g_show_outline_caller( g_xywindow_globals_private.show_outline );
2841 ToggleItem g_show_outline( g_show_outline_caller );
2842 void ShowOutlineToggle(){
2843 g_xywindow_globals_private.show_outline ^= 1;
2844 g_show_outline.update();
2845 XY_UpdateAllWindows();
2848 BoolExportCaller g_show_axes_caller( g_xywindow_globals_private.show_axis );
2849 ToggleItem g_show_axes( g_show_axes_caller );
2850 void ShowAxesToggle(){
2851 g_xywindow_globals_private.show_axis ^= 1;
2852 g_show_axes.update();
2853 XY_UpdateAllWindows();
2857 BoolExportCaller g_show_workzone_caller( g_xywindow_globals_private.d_show_work );
2858 ToggleItem g_show_workzone( g_show_workzone_caller );
2859 void ShowWorkzoneToggle(){
2860 g_xywindow_globals_private.d_show_work ^= 1;
2861 g_show_workzone.update();
2862 XY_UpdateAllWindows();
2866 void ShowAxesToggle(){
2867 g_xywindow_globals_private.show_axis ^= 1;
2868 XY_UpdateAllWindows();
2870 typedef FreeCaller<ShowAxesToggle> ShowAxesToggleCaller;
2871 void ShowAxesExport( const BoolImportCallback& importer ){
2872 importer( g_xywindow_globals_private.show_axis );
2874 typedef FreeCaller1<const BoolImportCallback&, ShowAxesExport> ShowAxesExportCaller;
2876 ShowAxesExportCaller g_show_axes_caller;
2877 BoolExportCallback g_show_axes_callback( g_show_axes_caller );
2878 ToggleItem g_show_axes( g_show_axes_callback );
2882 BoolExportCaller g_texdef_movelock_caller( g_brush_texturelock_enabled );
2883 ToggleItem g_texdef_movelock_item( g_texdef_movelock_caller );
2885 void Texdef_ToggleMoveLock(){
2886 g_brush_texturelock_enabled = !g_brush_texturelock_enabled;
2887 g_texdef_movelock_item.update();
2891 BoolExportCaller g_show_size_caller( g_xywindow_globals_private.m_bSizePaint );
2892 ToggleItem g_show_size_item( g_show_size_caller );
2893 void ToggleShowSizeInfo(){
2894 g_xywindow_globals_private.m_bSizePaint = !g_xywindow_globals_private.m_bSizePaint;
2895 g_show_size_item.update();
2896 XY_UpdateAllWindows();
2899 BoolExportCaller g_show_crosshair_caller( g_bCrossHairs );
2900 ToggleItem g_show_crosshair_item( g_show_crosshair_caller );
2901 void ToggleShowCrosshair(){
2903 g_show_crosshair_item.update();
2904 XY_UpdateAllWindows();
2907 BoolExportCaller g_show_grid_caller( g_xywindow_globals_private.d_showgrid );
2908 ToggleItem g_show_grid_item( g_show_grid_caller );
2909 void ToggleShowGrid(){
2910 g_xywindow_globals_private.d_showgrid = !g_xywindow_globals_private.d_showgrid;
2911 g_show_grid_item.update();
2912 XY_UpdateAllWindows();
2916 void XYShow_registerCommands(){
2917 GlobalToggles_insert( "ToggleSizePaint", FreeCaller<ToggleShowSizeInfo>(), ToggleItem::AddCallbackCaller( g_show_size_item ), Accelerator( 'J' ) );
2918 GlobalToggles_insert( "ToggleCrosshairs", FreeCaller<ToggleShowCrosshair>(), ToggleItem::AddCallbackCaller( g_show_crosshair_item ), Accelerator( 'X', (GdkModifierType)GDK_SHIFT_MASK ) );
2919 GlobalToggles_insert( "ToggleGrid", FreeCaller<ToggleShowGrid>(), ToggleItem::AddCallbackCaller( g_show_grid_item ), Accelerator( '0' ) );
2921 GlobalToggles_insert( "ShowAngles", FreeCaller<ShowAnglesToggle>(), ToggleItem::AddCallbackCaller( g_show_angles ) );
2922 GlobalToggles_insert( "ShowNames", FreeCaller<ShowNamesToggle>(), ToggleItem::AddCallbackCaller( g_show_names ) );
2923 GlobalToggles_insert( "ShowBlocks", FreeCaller<ShowBlocksToggle>(), ToggleItem::AddCallbackCaller( g_show_blocks ) );
2924 GlobalToggles_insert( "ShowCoordinates", FreeCaller<ShowCoordinatesToggle>(), ToggleItem::AddCallbackCaller( g_show_coordinates ) );
2925 GlobalToggles_insert( "ShowWindowOutline", FreeCaller<ShowOutlineToggle>(), ToggleItem::AddCallbackCaller( g_show_outline ) );
2926 GlobalToggles_insert( "ShowAxes", FreeCaller<ShowAxesToggle>(), ToggleItem::AddCallbackCaller( g_show_axes ) );
2927 GlobalToggles_insert( "ShowWorkzone", FreeCaller<ShowWorkzoneToggle>(), ToggleItem::AddCallbackCaller( g_show_workzone ) );
2930 void XYWnd_registerShortcuts(){
2931 command_connect_accelerator( "ToggleCrosshairs" );
2932 command_connect_accelerator( "ToggleSizePaint" );
2937 void Orthographic_constructPreferences( PreferencesPage& page ){
2938 page.appendCheckBox( "", "Solid selection boxes ( no stipple )", g_xywindow_globals.m_bNoStipple );
2939 //page.appendCheckBox( "", "Display size info", g_xywindow_globals_private.m_bSizePaint );
2940 page.appendCheckBox( "", "Chase mouse during drags", g_xywindow_globals_private.m_bChaseMouse );
2941 page.appendCheckBox( "", "Update views on camera move", g_xywindow_globals_private.m_bCamXYUpdate );
2943 void Orthographic_constructPage( PreferenceGroup& group ){
2944 PreferencesPage page( group.createPage( "Orthographic", "Orthographic View Preferences" ) );
2945 Orthographic_constructPreferences( page );
2947 void Orthographic_registerPreferencesPage(){
2948 PreferencesDialog_addSettingsPage( FreeCaller1<PreferenceGroup&, Orthographic_constructPage>() );
2951 void Clipper_constructPreferences( PreferencesPage& page ){
2952 page.appendCheckBox( "", "Clipper tool uses caulk", g_clip_useCaulk );
2954 void Clipper_constructPage( PreferenceGroup& group ){
2955 PreferencesPage page( group.createPage( "Clipper", "Clipper Tool Settings" ) );
2956 Clipper_constructPreferences( page );
2958 void Clipper_registerPreferencesPage(){
2959 PreferencesDialog_addSettingsPage( FreeCaller1<PreferenceGroup&, Clipper_constructPage>() );
2963 #include "preferencesystem.h"
2964 #include "stringio.h"
2969 void ToggleShown_importBool( ToggleShown& self, bool value ){
2972 typedef ReferenceCaller1<ToggleShown, bool, ToggleShown_importBool> ToggleShownImportBoolCaller;
2973 void ToggleShown_exportBool( const ToggleShown& self, const BoolImportCallback& importer ){
2974 importer( self.active() );
2976 typedef ConstReferenceCaller1<ToggleShown, const BoolImportCallback&, ToggleShown_exportBool> ToggleShownExportBoolCaller;
2979 void XYWindow_Construct(){
2980 // GlobalCommands_insert( "ToggleCrosshairs", FreeCaller<ToggleShowCrosshair>(), Accelerator( 'X', (GdkModifierType)GDK_SHIFT_MASK ) );
2981 // GlobalCommands_insert( "ToggleSizePaint", FreeCaller<ToggleShowSizeInfo>(), Accelerator( 'J' ) );
2982 // GlobalCommands_insert( "ToggleGrid", FreeCaller<ToggleShowGrid>(), Accelerator( '0' ) );
2984 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 ) ) );
2985 GlobalToggles_insert( "ToggleSideView", ToggleShown::ToggleCaller( g_yz_side_shown ), ToggleItem::AddCallbackCaller( g_yz_side_shown.m_item ) );
2986 GlobalToggles_insert( "ToggleFrontView", ToggleShown::ToggleCaller( g_xz_front_shown ), ToggleItem::AddCallbackCaller( g_xz_front_shown.m_item ) );
2987 GlobalCommands_insert( "NextView", FreeCaller<XY_Next>(), Accelerator( GDK_Tab, (GdkModifierType)GDK_CONTROL_MASK ) );
2988 GlobalCommands_insert( "ZoomIn", FreeCaller<XY_ZoomIn>(), Accelerator( GDK_Delete ) );
2989 GlobalCommands_insert( "ZoomOut", FreeCaller<XY_ZoomOut>(), Accelerator( GDK_Insert ) );
2990 GlobalCommands_insert( "ViewTop", FreeCaller<XY_Top>(), Accelerator( GDK_KP_Home ) );
2991 GlobalCommands_insert( "ViewSide", FreeCaller<XY_Side>(), Accelerator( GDK_KP_Page_Down ) );
2992 GlobalCommands_insert( "ViewFront", FreeCaller<XY_Front>(), Accelerator( GDK_KP_End ) );
2993 GlobalCommands_insert( "Zoom100", FreeCaller<XY_Zoom100>() );
2994 GlobalCommands_insert( "CenterXYView", FreeCaller<XY_Focus>(), Accelerator( GDK_Tab, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
2996 GlobalPreferenceSystem().registerPreference( "ClipCaulk", BoolImportStringCaller( g_clip_useCaulk ), BoolExportStringCaller( g_clip_useCaulk ) );
2998 GlobalPreferenceSystem().registerPreference( "NewRightClick", BoolImportStringCaller( g_xywindow_globals.m_bRightClick ), BoolExportStringCaller( g_xywindow_globals.m_bRightClick ) );
2999 GlobalPreferenceSystem().registerPreference( "ImprovedWheelZoom", BoolImportStringCaller( g_xywindow_globals.m_bImprovedWheelZoom ), BoolExportStringCaller( g_xywindow_globals.m_bImprovedWheelZoom ) );
3000 GlobalPreferenceSystem().registerPreference( "ChaseMouse", BoolImportStringCaller( g_xywindow_globals_private.m_bChaseMouse ), BoolExportStringCaller( g_xywindow_globals_private.m_bChaseMouse ) );
3001 GlobalPreferenceSystem().registerPreference( "SizePainting", BoolImportStringCaller( g_xywindow_globals_private.m_bSizePaint ), BoolExportStringCaller( g_xywindow_globals_private.m_bSizePaint ) );
3002 GlobalPreferenceSystem().registerPreference( "ShowCrosshair", BoolImportStringCaller( g_bCrossHairs ), BoolExportStringCaller( g_bCrossHairs ) );
3003 GlobalPreferenceSystem().registerPreference( "NoStipple", BoolImportStringCaller( g_xywindow_globals.m_bNoStipple ), BoolExportStringCaller( g_xywindow_globals.m_bNoStipple ) );
3004 GlobalPreferenceSystem().registerPreference( "SI_ShowCoords", BoolImportStringCaller( g_xywindow_globals_private.show_coordinates ), BoolExportStringCaller( g_xywindow_globals_private.show_coordinates ) );
3005 GlobalPreferenceSystem().registerPreference( "SI_ShowOutlines", BoolImportStringCaller( g_xywindow_globals_private.show_outline ), BoolExportStringCaller( g_xywindow_globals_private.show_outline ) );
3006 GlobalPreferenceSystem().registerPreference( "SI_ShowAxis", BoolImportStringCaller( g_xywindow_globals_private.show_axis ), BoolExportStringCaller( g_xywindow_globals_private.show_axis ) );
3007 GlobalPreferenceSystem().registerPreference( "CamXYUpdate", BoolImportStringCaller( g_xywindow_globals_private.m_bCamXYUpdate ), BoolExportStringCaller( g_xywindow_globals_private.m_bCamXYUpdate ) );
3008 GlobalPreferenceSystem().registerPreference( "ShowWorkzone", BoolImportStringCaller( g_xywindow_globals_private.d_show_work ), BoolExportStringCaller( g_xywindow_globals_private.d_show_work ) );
3010 GlobalPreferenceSystem().registerPreference( "SI_AxisColors0", Vector3ImportStringCaller( g_xywindow_globals.AxisColorX ), Vector3ExportStringCaller( g_xywindow_globals.AxisColorX ) );
3011 GlobalPreferenceSystem().registerPreference( "SI_AxisColors1", Vector3ImportStringCaller( g_xywindow_globals.AxisColorY ), Vector3ExportStringCaller( g_xywindow_globals.AxisColorY ) );
3012 GlobalPreferenceSystem().registerPreference( "SI_AxisColors2", Vector3ImportStringCaller( g_xywindow_globals.AxisColorZ ), Vector3ExportStringCaller( g_xywindow_globals.AxisColorZ ) );
3013 GlobalPreferenceSystem().registerPreference( "SI_Colors1", Vector3ImportStringCaller( g_xywindow_globals.color_gridback ), Vector3ExportStringCaller( g_xywindow_globals.color_gridback ) );
3014 GlobalPreferenceSystem().registerPreference( "SI_Colors2", Vector3ImportStringCaller( g_xywindow_globals.color_gridminor ), Vector3ExportStringCaller( g_xywindow_globals.color_gridminor ) );
3015 GlobalPreferenceSystem().registerPreference( "SI_Colors3", Vector3ImportStringCaller( g_xywindow_globals.color_gridmajor ), Vector3ExportStringCaller( g_xywindow_globals.color_gridmajor ) );
3016 GlobalPreferenceSystem().registerPreference( "SI_Colors6", Vector3ImportStringCaller( g_xywindow_globals.color_gridblock ), Vector3ExportStringCaller( g_xywindow_globals.color_gridblock ) );
3017 GlobalPreferenceSystem().registerPreference( "SI_Colors7", Vector3ImportStringCaller( g_xywindow_globals.color_gridtext ), Vector3ExportStringCaller( g_xywindow_globals.color_gridtext ) );
3018 GlobalPreferenceSystem().registerPreference( "SI_Colors8", Vector3ImportStringCaller( g_xywindow_globals.color_brushes ), Vector3ExportStringCaller( g_xywindow_globals.color_brushes ) );
3019 GlobalPreferenceSystem().registerPreference( "SI_Colors9", Vector3ImportStringCaller( g_xywindow_globals.color_viewname ), Vector3ExportStringCaller( g_xywindow_globals.color_viewname ) );
3020 GlobalPreferenceSystem().registerPreference( "SI_Colors10", Vector3ImportStringCaller( g_xywindow_globals.color_clipper ), Vector3ExportStringCaller( g_xywindow_globals.color_clipper ) );
3021 GlobalPreferenceSystem().registerPreference( "SI_Colors11", Vector3ImportStringCaller( g_xywindow_globals.color_selbrushes ), Vector3ExportStringCaller( g_xywindow_globals.color_selbrushes ) );
3024 GlobalPreferenceSystem().registerPreference( "XZVIS", makeBoolStringImportCallback( ToggleShownImportBoolCaller( g_xz_front_shown ) ), makeBoolStringExportCallback( ToggleShownExportBoolCaller( g_xz_front_shown ) ) );
3025 GlobalPreferenceSystem().registerPreference( "YZVIS", makeBoolStringImportCallback( ToggleShownImportBoolCaller( g_yz_side_shown ) ), makeBoolStringExportCallback( ToggleShownExportBoolCaller( g_yz_side_shown ) ) );
3027 Orthographic_registerPreferencesPage();
3028 Clipper_registerPreferencesPage();
3030 XYWnd::captureStates();
3031 GlobalEntityClassManager().attach( g_EntityClassMenu );
3034 void XYWindow_Destroy(){
3035 GlobalEntityClassManager().detach( g_EntityClassMenu );
3036 XYWnd::releaseStates();