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;
354 // bool m_bCamXYUpdate;
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 );
1014 return RAD_CONTROL | RAD_MBUTTON;
1017 void XYWnd_PositionCamera( XYWnd* xywnd, int x, int y, CamWnd& camwnd ){
1018 Vector3 origin( Camera_getOrigin( camwnd ) );
1019 xywnd->XY_ToPoint( x, y, origin );
1020 xywnd->XY_SnapToGrid( origin );
1021 Camera_setOrigin( camwnd, origin );
1024 unsigned int OrientCamera_buttons(){
1025 // if ( g_glwindow_globals.m_nMouseType == ETwoButton ) {
1026 // return RAD_RBUTTON | RAD_SHIFT | RAD_CONTROL;
1031 void XYWnd_OrientCamera( XYWnd* xywnd, int x, int y, CamWnd& camwnd ){
1032 //globalOutputStream() << Camera_getAngles( camwnd ) << " b4\n";
1033 Vector3 point = g_vector3_identity;
1034 xywnd->XY_ToPoint( x, y, point );
1035 //xywnd->XY_SnapToGrid( point );
1036 vector3_subtract( point, Camera_getOrigin( camwnd ) );
1038 int n1 = ( xywnd->GetViewType() == XY ) ? 1 : 2;
1039 int n2 = ( xywnd->GetViewType() == YZ ) ? 1 : 0;
1040 int nAngle = ( xywnd->GetViewType() == XY ) ? CAMERA_YAW : CAMERA_PITCH;
1041 if ( point[n1] || point[n2] ) {
1042 Vector3 angles( Camera_getAngles( camwnd ) );
1043 angles[nAngle] = static_cast<float>( radians_to_degrees( atan2( point[n1], point[n2] ) ) );
1044 if( angles[CAMERA_YAW] < 0 )
1045 angles[CAMERA_YAW] = angles[CAMERA_YAW] + 360;
1046 if ( nAngle == CAMERA_PITCH ){
1047 if( fabs( angles[CAMERA_PITCH] ) > 90 ){
1048 angles[CAMERA_PITCH] = ( angles[CAMERA_PITCH] > 0 ) ? ( -angles[CAMERA_PITCH] + 180 ) : ( -angles[CAMERA_PITCH] - 180 );
1049 if( xywnd->GetViewType() == YZ ){
1050 if( angles[CAMERA_YAW] < 180 ){
1051 angles[CAMERA_YAW] = 360 - angles[CAMERA_YAW];
1054 else if( angles[CAMERA_YAW] < 90 || angles[CAMERA_YAW] > 270 ){
1055 angles[CAMERA_YAW] = 180 - angles[CAMERA_YAW];
1059 if( xywnd->GetViewType() == YZ ){
1060 if( angles[CAMERA_YAW] > 180 ){
1061 angles[CAMERA_YAW] = 360 - angles[CAMERA_YAW];
1064 else if( angles[CAMERA_YAW] > 90 && angles[CAMERA_YAW] < 270 ){
1065 angles[CAMERA_YAW] = 180 - angles[CAMERA_YAW];
1069 Camera_setAngles( camwnd, angles );
1071 //globalOutputStream() << Camera_getAngles( camwnd ) << "\n";
1074 unsigned int SetCustomPivotOrigin_buttons(){
1075 return RAD_MBUTTON | RAD_SHIFT;
1083 unsigned int NewBrushDrag_buttons(){
1087 void XYWnd::NewBrushDrag_Begin( int x, int y ){
1089 m_nNewBrushPressx = x;
1090 m_nNewBrushPressy = y;
1092 m_bNewBrushDrag = true;
1093 GlobalUndoSystem().start();
1096 void XYWnd::NewBrushDrag_End( int x, int y ){
1097 if ( m_NewBrushDrag != 0 ) {
1098 GlobalUndoSystem().finish( "brushDragNew" );
1102 void XYWnd::NewBrushDrag( int x, int y ){
1104 XY_ToPoint( m_nNewBrushPressx, m_nNewBrushPressy, mins );
1105 XY_SnapToGrid( mins );
1106 XY_ToPoint( x, y, maxs );
1107 XY_SnapToGrid( maxs );
1109 int nDim = ( m_viewType == XY ) ? 2 : ( m_viewType == YZ ) ? 0 : 1;
1111 mins[nDim] = float_snapped( Select_getWorkZone().d_work_min[nDim], GetSnapGridSize() );
1112 maxs[nDim] = float_snapped( Select_getWorkZone().d_work_max[nDim], GetSnapGridSize() );
1114 if ( maxs[nDim] <= mins[nDim] ) {
1115 maxs[nDim] = mins[nDim] + GetGridSize();
1118 for ( int i = 0 ; i < 3 ; i++ )
1120 if ( mins[i] == maxs[i] ) {
1121 return; // don't create a degenerate brush
1123 if ( mins[i] > maxs[i] ) {
1124 float temp = mins[i];
1130 if ( m_NewBrushDrag == 0 ) {
1131 NodeSmartReference node( GlobalBrushCreator().createBrush() );
1132 Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->insert( node );
1134 scene::Path brushpath( makeReference( GlobalSceneGraph().root() ) );
1135 brushpath.push( makeReference( *Map_GetWorldspawn( g_map ) ) );
1136 brushpath.push( makeReference( node.get() ) );
1137 selectPath( brushpath, true );
1139 m_NewBrushDrag = node.get_pointer();
1143 //Scene_BrushResize_Selected(GlobalSceneGraph(), aabb_for_minmax(mins, maxs), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()));
1144 Scene_BrushResize_Selected( GlobalSceneGraph(), aabb_for_minmax( mins, maxs ),
1145 g_brush_always_caulk ?
1146 "textures/common/caulk" : TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ) );
1149 void entitycreate_activated( GtkWidget* item ){
1150 scene::Node* world_node = Map_FindWorldspawn( g_map );
1151 const char* entity_name = gtk_label_get_text( GTK_LABEL( GTK_BIN( item )->child ) );
1153 if ( !( world_node && string_equal( entity_name, "worldspawn" ) ) ) {
1154 g_pParentWnd->ActiveXY()->OnEntityCreate( entity_name );
1157 GlobalRadiant().m_pfnMessageBox( GTK_WIDGET( MainFrame_getWindow() ), "There's already a worldspawn in your map!"
1165 void EntityClassMenu_addItem( GtkMenu* menu, const char* name ){
1166 GtkMenuItem* item = GTK_MENU_ITEM( gtk_menu_item_new_with_label( name ) );
1167 g_signal_connect( G_OBJECT( item ), "activate", G_CALLBACK( entitycreate_activated ), item );
1168 gtk_widget_show( GTK_WIDGET( item ) );
1169 menu_add_item( menu, item );
1172 class EntityClassMenuInserter : public EntityClassVisitor
1174 typedef std::pair<GtkMenu*, CopiedString> MenuPair;
1175 typedef std::vector<MenuPair> MenuStack;
1177 CopiedString m_previous;
1179 EntityClassMenuInserter( GtkMenu* menu ){
1180 m_stack.reserve( 2 );
1181 m_stack.push_back( MenuPair( menu, "" ) );
1183 ~EntityClassMenuInserter(){
1184 if ( !string_empty( m_previous.c_str() ) ) {
1185 addItem( m_previous.c_str(), "" );
1188 void visit( EntityClass* e ){
1189 ASSERT_MESSAGE( !string_empty( e->name() ), "entity-class has no name" );
1190 if ( !string_empty( m_previous.c_str() ) ) {
1191 addItem( m_previous.c_str(), e->name() );
1193 m_previous = e->name();
1195 void pushMenu( const CopiedString& name ){
1196 GtkMenuItem* item = GTK_MENU_ITEM( gtk_menu_item_new_with_label( name.c_str() ) );
1197 gtk_widget_show( GTK_WIDGET( item ) );
1198 container_add_widget( GTK_CONTAINER( m_stack.back().first ), GTK_WIDGET( item ) );
1200 GtkMenu* submenu = GTK_MENU( gtk_menu_new() );
1201 gtk_menu_item_set_submenu( item, GTK_WIDGET( submenu ) );
1203 m_stack.push_back( MenuPair( submenu, name ) );
1208 void addItem( const char* name, const char* next ){
1209 const char* underscore = strchr( name, '_' );
1211 if ( underscore != 0 && underscore != name ) {
1212 bool nextEqual = string_equal_n( name, next, ( underscore + 1 ) - name );
1213 const char* parent = m_stack.back().second.c_str();
1215 if ( !string_empty( parent )
1216 && string_length( parent ) == std::size_t( underscore - name )
1217 && string_equal_n( name, parent, underscore - name ) ) { // this is a child
1219 else if ( nextEqual ) {
1220 if ( m_stack.size() == 2 ) {
1223 pushMenu( CopiedString( StringRange( name, underscore ) ) );
1225 else if ( m_stack.size() == 2 ) {
1229 else if ( m_stack.size() == 2 ) {
1233 EntityClassMenu_addItem( m_stack.back().first, name );
1237 void XYWnd::OnContextMenu(){
1238 // if ( g_xywindow_globals.m_bRightClick == false ) {
1242 if ( m_mnuDrop == 0 ) { // first time, load it up
1243 GtkMenu* menu = m_mnuDrop = GTK_MENU( gtk_menu_new() );
1245 EntityClassMenuInserter inserter( menu );
1246 GlobalEntityClassManager().forEach( inserter );
1249 gtk_menu_popup( m_mnuDrop, 0, 0, 0, 0, 1, GDK_CURRENT_TIME );
1252 FreezePointer g_xywnd_freezePointer;
1254 unsigned int Move_buttons(){
1258 void XYWnd_moveDelta( int x, int y, unsigned int state, void* data ){
1259 reinterpret_cast<XYWnd*>( data )->EntityCreate_MouseMove( x, y );
1260 reinterpret_cast<XYWnd*>( data )->Scroll( -x, y );
1263 gboolean XYWnd_Move_focusOut( GtkWidget* widget, GdkEventFocus* event, XYWnd* xywnd ){
1268 void XYWnd::Move_Begin(){
1269 if ( m_move_started ) {
1272 m_move_started = true;
1273 g_xywnd_freezePointer.freeze_pointer( m_parent != 0 ? m_parent : MainFrame_getWindow(), m_gl_widget, XYWnd_moveDelta, this );
1274 m_move_focusOut = g_signal_connect( G_OBJECT( m_gl_widget ), "focus_out_event", G_CALLBACK( XYWnd_Move_focusOut ), this );
1277 void XYWnd::Move_End(){
1278 m_move_started = false;
1279 g_xywnd_freezePointer.unfreeze_pointer( m_parent != 0 ? m_parent : MainFrame_getWindow(), false );
1280 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_move_focusOut );
1283 unsigned int Zoom_buttons(){
1284 return RAD_RBUTTON | RAD_ALT;
1289 void XYWnd_zoomDelta( int x, int y, unsigned int state, void* data ){
1292 while ( abs( g_dragZoom ) > 8 )
1294 if ( g_dragZoom > 0 ) {
1295 reinterpret_cast<XYWnd*>( data )->ZoomOut();
1300 reinterpret_cast<XYWnd*>( data )->ZoomIn();
1307 gboolean XYWnd_Zoom_focusOut( GtkWidget* widget, GdkEventFocus* event, XYWnd* xywnd ){
1312 void XYWnd::Zoom_Begin(){
1313 if ( m_zoom_started ) {
1316 m_zoom_started = true;
1318 g_xywnd_freezePointer.freeze_pointer( m_parent != 0 ? m_parent : MainFrame_getWindow(), m_gl_widget, XYWnd_zoomDelta, this );
1319 m_zoom_focusOut = g_signal_connect( G_OBJECT( m_gl_widget ), "focus_out_event", G_CALLBACK( XYWnd_Zoom_focusOut ), this );
1322 void XYWnd::Zoom_End(){
1323 m_zoom_started = false;
1324 g_xywnd_freezePointer.unfreeze_pointer( m_parent != 0 ? m_parent : MainFrame_getWindow(), false );
1325 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_zoom_focusOut );
1328 // makes sure the selected brush or camera is in view
1329 void XYWnd::PositionView( const Vector3& position ){
1330 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1331 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1333 m_vOrigin[nDim1] = position[nDim1];
1334 m_vOrigin[nDim2] = position[nDim2];
1338 XYWnd_Update( *this );
1341 void XYWnd::SetViewType( VIEWTYPE viewType ){
1342 m_viewType = viewType;
1345 if ( m_parent != 0 ) {
1346 gtk_window_set_title( m_parent, ViewType_getTitle( m_viewType ) );
1351 inline WindowVector WindowVector_forInteger( int x, int y ){
1352 return WindowVector( static_cast<float>( x ), static_cast<float>( y ) );
1355 void XYWnd::mouseDown( const WindowVector& position, ButtonIdentifier button, ModifierFlags modifiers ){
1356 XY_MouseDown( static_cast<int>( position.x() ), static_cast<int>( position.y() ), buttons_for_button_and_modifiers( button, modifiers ) );
1358 void XYWnd::XY_MouseDown( int x, int y, unsigned int buttons ){
1359 if ( buttons == Move_buttons() ) {
1361 EntityCreate_MouseDown( x, y );
1363 else if ( buttons == Zoom_buttons() ) {
1366 else if ( ClipMode() && ( buttons == Clipper_buttons() || buttons == Clipper_quick_buttons() ) ) {
1367 Clipper_OnLButtonDown( x, y );
1369 else if ( !ClipMode() && buttons == Clipper_quick_buttons() ) {
1371 g_quick_clipper = true;
1372 Clipper_OnLButtonDown( x, y );
1374 else if ( buttons == NewBrushDrag_buttons() && GlobalSelectionSystem().countSelected() == 0 ) {
1375 NewBrushDrag_Begin( x, y );
1377 // control mbutton = move camera
1378 else if ( buttons == MoveCamera_buttons() ) {
1379 XYWnd_PositionCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1381 // mbutton = angle camera
1382 else if ( buttons == OrientCamera_buttons() ) {
1383 XYWnd_OrientCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1385 else if ( buttons == SetCustomPivotOrigin_buttons() ) {
1386 SetCustomPivotOrigin( x, y );
1390 m_window_observer->onMouseDown( WindowVector_forInteger( x, y ), button_for_flags( buttons ), modifiers_for_flags( buttons ) );
1394 void XYWnd::XY_MouseUp( int x, int y, unsigned int buttons ){
1395 if ( m_move_started ) {
1397 EntityCreate_MouseUp( x, y );
1399 else if ( m_zoom_started ) {
1402 else if ( ClipMode() && ( buttons == Clipper_buttons() || buttons == Clipper_quick_buttons() ) ) {
1403 Clipper_OnLButtonUp( x, y );
1405 else if ( m_bNewBrushDrag ) {
1406 m_bNewBrushDrag = false;
1407 NewBrushDrag_End( x, y );
1408 if ( m_NewBrushDrag == 0 ) {
1409 //L button w/o created brush = tunnel selection
1410 m_window_observer->onMouseUp( WindowVector_forInteger( x, y ), button_for_flags( buttons ), modifiers_for_flags( buttons ) );
1415 m_window_observer->onMouseUp( WindowVector_forInteger( x, y ), button_for_flags( buttons ), modifiers_for_flags( buttons ) );
1419 void XYWnd::XY_MouseMoved( int x, int y, unsigned int buttons ){
1420 // rbutton = drag xy origin
1421 if ( m_move_started ) {
1424 else if ( m_zoom_started ) {
1427 else if ( ClipMode() && g_pMovingClip != 0 ) {
1428 Clipper_OnMouseMoved( x, y );
1430 // lbutton without selection = drag new brush
1431 else if ( m_bNewBrushDrag ) {
1432 NewBrushDrag( x, y );
1435 // control mbutton = move camera
1436 else if ( buttons == MoveCamera_buttons() ) {
1437 XYWnd_PositionCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1440 // mbutton = angle camera
1441 else if ( buttons == OrientCamera_buttons() ) {
1442 XYWnd_OrientCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1445 else if ( buttons == SetCustomPivotOrigin_buttons() ) {
1446 SetCustomPivotOrigin( x, y );
1451 m_window_observer->onMouseMotion( WindowVector_forInteger( x, y ), modifiers_for_flags( buttons ) );
1453 m_mousePosition[0] = m_mousePosition[1] = m_mousePosition[2] = 0.0;
1454 XY_ToPoint( x, y, m_mousePosition );
1455 XY_SnapToGrid( m_mousePosition );
1457 StringOutputStream status( 64 );
1458 status << "x:: " << FloatFormat( m_mousePosition[0], 6, 1 )
1459 << " y:: " << FloatFormat( m_mousePosition[1], 6, 1 )
1460 << " z:: " << FloatFormat( m_mousePosition[2], 6, 1 );
1461 g_pParentWnd->SetStatusText( g_pParentWnd->m_position_status, status.c_str() );
1463 if ( g_bCrossHairs ) {
1464 XYWnd_Update( *this );
1467 Clipper_Crosshair_OnMouseMoved( x, y );
1471 void XYWnd::EntityCreate_MouseDown( int x, int y ){
1472 m_entityCreate = true;
1473 m_entityCreate_x = x;
1474 m_entityCreate_y = y;
1477 void XYWnd::EntityCreate_MouseMove( int x, int y ){
1478 if ( m_entityCreate && ( m_entityCreate_x != x || m_entityCreate_y != y ) ) {
1479 m_entityCreate = false;
1483 void XYWnd::EntityCreate_MouseUp( int x, int y ){
1484 if ( m_entityCreate ) {
1485 m_entityCreate = false;
1490 inline float screen_normalised( int pos, unsigned int size ){
1491 return ( ( 2.0f * pos ) / size ) - 1.0f;
1494 inline float normalised_to_world( float normalised, float world_origin, float normalised2world_scale ){
1495 return world_origin + normalised * normalised2world_scale;
1499 // TTimo: watch it, this doesn't init one of the 3 coords
1500 void XYWnd::XY_ToPoint( int x, int y, Vector3& point ){
1501 float normalised2world_scale_x = m_nWidth / 2 / m_fScale;
1502 float normalised2world_scale_y = m_nHeight / 2 / m_fScale;
1503 if ( m_viewType == XY ) {
1504 point[0] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[0], normalised2world_scale_x );
1505 point[1] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[1], normalised2world_scale_y );
1507 else if ( m_viewType == YZ ) {
1508 point[1] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[1], normalised2world_scale_x );
1509 point[2] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[2], normalised2world_scale_y );
1513 point[0] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[0], normalised2world_scale_x );
1514 point[2] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[2], normalised2world_scale_y );
1518 void XYWnd::XY_SnapToGrid( Vector3& point ){
1519 if ( m_viewType == XY ) {
1520 point[0] = float_snapped( point[0], GetSnapGridSize() );
1521 point[1] = float_snapped( point[1], GetSnapGridSize() );
1523 else if ( m_viewType == YZ ) {
1524 point[1] = float_snapped( point[1], GetSnapGridSize() );
1525 point[2] = float_snapped( point[2], GetSnapGridSize() );
1529 point[0] = float_snapped( point[0], GetSnapGridSize() );
1530 point[2] = float_snapped( point[2], GetSnapGridSize() );
1534 void XYWnd::XY_LoadBackgroundImage( const char *name ){
1535 const char* relative = path_make_relative( name, GlobalFileSystem().findRoot( name ) );
1536 if ( relative == name ) {
1537 globalOutputStream() << "WARNING: could not extract the relative path, using full path instead\n";
1540 char fileNameWithoutExt[512];
1541 strncpy( fileNameWithoutExt, relative, sizeof( fileNameWithoutExt ) - 1 );
1542 fileNameWithoutExt[512 - 1] = '\0';
1543 fileNameWithoutExt[strlen( fileNameWithoutExt ) - 4] = '\0';
1545 Image *image = QERApp_LoadImage( 0, fileNameWithoutExt );
1547 globalOutputStream() << "Could not load texture " << fileNameWithoutExt << "\n";
1550 g_pParentWnd->ActiveXY()->m_tex = (qtexture_t*)malloc( sizeof( qtexture_t ) );
1551 LoadTextureRGBA( g_pParentWnd->ActiveXY()->XYWnd::m_tex, image->getRGBAPixels(), image->getWidth(), image->getHeight() );
1552 globalOutputStream() << "Loaded background texture " << relative << "\n";
1553 g_pParentWnd->ActiveXY()->m_backgroundActivated = true;
1556 switch ( g_pParentWnd->ActiveXY()->m_viewType )
1573 Select_GetBounds( min, max );
1574 g_pParentWnd->ActiveXY()->m_xmin = min[m_ix];
1575 g_pParentWnd->ActiveXY()->m_ymin = min[m_iy];
1576 g_pParentWnd->ActiveXY()->m_xmax = max[m_ix];
1577 g_pParentWnd->ActiveXY()->m_ymax = max[m_iy];
1580 void XYWnd::XY_DisableBackground( void ){
1581 g_pParentWnd->ActiveXY()->m_backgroundActivated = false;
1582 if ( g_pParentWnd->ActiveXY()->m_tex ) {
1583 free( g_pParentWnd->ActiveXY()->m_tex );
1585 g_pParentWnd->ActiveXY()->m_tex = NULL;
1588 void WXY_BackgroundSelect( void ){
1589 bool brushesSelected = Scene_countSelectedBrushes( GlobalSceneGraph() ) != 0;
1590 if ( !brushesSelected ) {
1591 gtk_MessageBox( 0, "You have to select some brushes to get the bounding box for.\n",
1592 "No selection", eMB_OK, eMB_ICONERROR );
1596 const char *filename = file_dialog( GTK_WIDGET( MainFrame_getWindow() ), TRUE, "Background Image", NULL, NULL );
1597 g_pParentWnd->ActiveXY()->XY_DisableBackground();
1599 g_pParentWnd->ActiveXY()->XY_LoadBackgroundImage( filename );
1604 ============================================================================
1608 ============================================================================
1617 double two_to_the_power( int power ){
1618 return pow( 2.0f, power );
1621 void XYWnd::XY_DrawAxis( void ){
1622 if ( g_xywindow_globals_private.show_axis ) {
1623 const char g_AxisName[3] = { 'X', 'Y', 'Z' };
1624 const int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1625 const int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1626 const int w = ( m_nWidth / 2 / m_fScale );
1627 const int h = ( m_nHeight / 2 / m_fScale );
1629 Vector3 colourX = ( m_viewType == YZ ) ? g_xywindow_globals.AxisColorY : g_xywindow_globals.AxisColorX;
1630 Vector3 colourY = ( m_viewType == XY ) ? g_xywindow_globals.AxisColorY : g_xywindow_globals.AxisColorZ;
1632 float grayX = vector3_dot( colourX, Vector3( 0.2989, 0.5870, 0.1140 ) );
1633 float grayY = vector3_dot( colourY, Vector3( 0.2989, 0.5870, 0.1140 ) );
1634 colourX[0] = colourX[1] = colourX[2] = grayX;
1635 colourY[0] = colourY[1] = colourY[2] = grayY;
1638 // draw two lines with corresponding axis colors to highlight current view
1639 // horizontal line: nDim1 color
1641 glBegin( GL_LINES );
1642 glColor3fv( vector3_to_array( colourX ) );
1643 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1644 glVertex2f( m_vOrigin[nDim1] - w + 65 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1646 glVertex2f( 32 / m_fScale, 0 );
1647 glColor3fv( vector3_to_array( colourY ) );
1648 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1649 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 20 / m_fScale );
1651 glVertex2f( 0, 32 / m_fScale );
1654 // now print axis symbols
1655 glColor3fv( vector3_to_array( colourX ) );
1656 glRasterPos2f( m_vOrigin[nDim1] - w + 55 / m_fScale, m_vOrigin[nDim2] + h - 55 / m_fScale );
1657 GlobalOpenGL().drawChar( g_AxisName[nDim1] );
1658 glRasterPos2f( 28 / m_fScale, -10 / m_fScale );
1659 GlobalOpenGL().drawChar( g_AxisName[nDim1] );
1660 glColor3fv( vector3_to_array( colourY ) );
1661 glRasterPos2f( m_vOrigin[nDim1] - w + 25 / m_fScale, m_vOrigin[nDim2] + h - 30 / m_fScale );
1662 GlobalOpenGL().drawChar( g_AxisName[nDim2] );
1663 glRasterPos2f( -10 / m_fScale, 28 / m_fScale );
1664 GlobalOpenGL().drawChar( g_AxisName[nDim2] );
1668 void XYWnd::RenderActive( void ){
1669 if ( glwidget_make_current( m_gl_widget ) != FALSE ) {
1670 if ( Map_Valid( g_map ) && ScreenUpdates_Enabled() ) {
1671 GlobalOpenGL_debugAssertNoErrors();
1672 glDrawBuffer( GL_FRONT );
1674 if ( g_xywindow_globals_private.show_outline ) {
1675 glMatrixMode( GL_PROJECTION );
1677 glOrtho( 0, m_nWidth, 0, m_nHeight, 0, 1 );
1679 glMatrixMode( GL_MODELVIEW );
1682 if( !Active() ){ //sorta erase
1683 glColor3fv( vector3_to_array( g_xywindow_globals.color_gridmajor ) );
1685 // four view mode doesn't colorize
1686 else if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) {
1687 glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) );
1691 switch ( m_viewType )
1694 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorX ) );
1697 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorY ) );
1700 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorZ ) );
1704 glBegin( GL_LINE_LOOP );
1705 glVertex2f( 0.5, 0.5 );
1706 glVertex2f( m_nWidth - 0.5, 1 );
1707 glVertex2f( m_nWidth - 0.5, m_nHeight - 0.5 );
1708 glVertex2f( 0.5, m_nHeight - 0.5 );
1711 // we do this part (the old way) only if show_axis is disabled
1712 if ( !g_xywindow_globals_private.show_axis ) {
1713 glMatrixMode( GL_PROJECTION );
1715 glOrtho( 0, m_nWidth, 0, m_nHeight, 0, 1 );
1717 glMatrixMode( GL_MODELVIEW );
1721 glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) );
1724 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridtext, 1.0f ) ) );
1727 glDisable( GL_BLEND );
1728 glRasterPos2f( 35, m_nHeight - 20 );
1730 GlobalOpenGL().drawString( ViewType_getTitle( m_viewType ) );
1734 glViewport( 0, 0, m_nWidth, m_nHeight );
1736 glMatrixMode( GL_PROJECTION );
1737 glLoadMatrixf( reinterpret_cast<const float*>( &m_projection ) );
1739 glMatrixMode( GL_MODELVIEW );
1741 glScalef( m_fScale, m_fScale, 1 );
1742 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1743 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1744 glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 );
1746 glDisable( GL_LINE_STIPPLE );
1747 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
1748 glDisableClientState( GL_NORMAL_ARRAY );
1749 glDisableClientState( GL_COLOR_ARRAY );
1750 glDisable( GL_TEXTURE_2D );
1751 glDisable( GL_LIGHTING );
1752 glDisable( GL_COLOR_MATERIAL );
1753 glDisable( GL_DEPTH_TEST );
1754 glDisable( GL_TEXTURE_1D );
1755 glDisable( GL_BLEND );
1757 XYWnd::XY_DrawAxis();
1760 glDrawBuffer( GL_BACK );
1761 GlobalOpenGL_debugAssertNoErrors();
1762 glwidget_make_current( m_gl_widget );
1767 void XYWnd::XY_DrawBackground( void ){
1768 glPushAttrib( GL_ALL_ATTRIB_BITS );
1770 glEnable( GL_TEXTURE_2D );
1771 glEnable( GL_BLEND );
1772 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
1773 glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1774 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
1775 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
1777 glPolygonMode( GL_FRONT, GL_FILL );
1779 glBindTexture( GL_TEXTURE_2D, m_tex->texture_number );
1780 glBegin( GL_QUADS );
1782 glColor4f( 1.0, 1.0, 1.0, m_alpha );
1783 glTexCoord2f( 0.0, 1.0 );
1784 glVertex2f( m_xmin, m_ymin );
1786 glTexCoord2f( 1.0, 1.0 );
1787 glVertex2f( m_xmax, m_ymin );
1789 glTexCoord2f( 1.0, 0.0 );
1790 glVertex2f( m_xmax, m_ymax );
1792 glTexCoord2f( 0.0, 0.0 );
1793 glVertex2f( m_xmin, m_ymax );
1796 glBindTexture( GL_TEXTURE_2D, 0 );
1801 void XYWnd::XY_DrawGrid( void ) {
1802 float x, y, xb, xe, yb, ye;
1805 float step, minor_step, stepx, stepy;
1806 step = minor_step = stepx = stepy = GetGridSize();
1808 int minor_power = Grid_getPower();
1811 while ( ( minor_step * m_fScale ) <= 4.0f ) { // make sure minor grid spacing is at least 4 pixels on the screen
1815 int power = minor_power;
1816 while ( ( power % 3 ) != 0 || ( step * m_fScale ) <= 32.0f ) { // make sure major grid spacing is at least 32 pixels on the screen
1818 step = float(two_to_the_power( power ) );
1820 mask = ( 1 << ( power - minor_power ) ) - 1;
1821 while ( ( stepx * m_fScale ) <= 32.0f ) // text step x must be at least 32
1823 while ( ( stepy * m_fScale ) <= 32.0f ) // text step y must be at least 32
1826 a = ( ( GetSnapGridSize() > 0.0f ) ? 1.0f : 0.3f );
1828 glDisable( GL_TEXTURE_2D );
1829 glDisable( GL_TEXTURE_1D );
1830 glDisable( GL_DEPTH_TEST );
1831 glDisable( GL_BLEND );
1834 w = ( m_nWidth / 2 / m_fScale );
1835 h = ( m_nHeight / 2 / m_fScale );
1837 const int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1838 const int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1840 xb = m_vOrigin[nDim1] - w;
1841 if ( xb < region_mins[nDim1] ) {
1842 xb = region_mins[nDim1];
1844 xb = step * floor( xb / step );
1846 xe = m_vOrigin[nDim1] + w;
1847 if ( xe > region_maxs[nDim1] ) {
1848 xe = region_maxs[nDim1];
1850 xe = step * ceil( xe / step );
1852 yb = m_vOrigin[nDim2] - h;
1853 if ( yb < region_mins[nDim2] ) {
1854 yb = region_mins[nDim2];
1856 yb = step * floor( yb / step );
1858 ye = m_vOrigin[nDim2] + h;
1859 if ( ye > region_maxs[nDim2] ) {
1860 ye = region_maxs[nDim2];
1862 ye = step * ceil( ye / step );
1864 #define COLORS_DIFFER( a,b ) \
1865 ( ( a )[0] != ( b )[0] || \
1866 ( a )[1] != ( b )[1] || \
1867 ( a )[2] != ( b )[2] )
1870 // draw minor blocks
1871 if ( g_xywindow_globals_private.d_showgrid || a < 1.0f ) {
1873 glEnable( GL_BLEND );
1876 if ( COLORS_DIFFER( g_xywindow_globals.color_gridminor, g_xywindow_globals.color_gridback ) ) {
1877 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridminor, a ) ) );
1879 glBegin( GL_LINES );
1881 for ( x = xb ; x < xe ; x += minor_step, ++i ) {
1882 if ( ( i & mask ) != 0 ) {
1883 glVertex2f( x, yb );
1884 glVertex2f( x, ye );
1888 for ( y = yb ; y < ye ; y += minor_step, ++i ) {
1889 if ( ( i & mask ) != 0 ) {
1890 glVertex2f( xb, y );
1891 glVertex2f( xe, y );
1897 // draw major blocks
1898 if ( COLORS_DIFFER( g_xywindow_globals.color_gridmajor, g_xywindow_globals.color_gridminor ) ) {
1899 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridmajor, a ) ) );
1901 glBegin( GL_LINES );
1902 for ( x = xb ; x <= xe ; x += step ) {
1903 glVertex2f( x, yb );
1904 glVertex2f( x, ye );
1906 for ( y = yb ; y <= ye ; y += step ) {
1907 glVertex2f( xb, y );
1908 glVertex2f( xe, y );
1914 glDisable( GL_BLEND );
1918 // draw coordinate text if needed
1919 if ( g_xywindow_globals_private.show_coordinates ) {
1920 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridtext, 1.0f ) ) );
1921 float offx = m_vOrigin[nDim2] + h - ( 4 + GlobalOpenGL().m_font->getPixelAscent() ) / m_fScale;
1922 float offy = m_vOrigin[nDim1] - w + 4 / m_fScale;
1923 for ( x = xb - fmod( xb, stepx ); x <= xe ; x += stepx ) {
1924 glRasterPos2f( x, offx );
1925 sprintf( text, "%g", x );
1926 GlobalOpenGL().drawString( text );
1928 for ( y = yb - fmod( yb, stepy ); y <= ye ; y += stepy ) {
1929 glRasterPos2f( offy, y );
1930 sprintf( text, "%g", y );
1931 GlobalOpenGL().drawString( text );
1935 // we do this part (the old way) only if show_axis is disabled
1936 if ( !g_xywindow_globals_private.show_axis ) {
1938 glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) );
1941 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridtext, 1.0f ) ) );
1944 glRasterPos2f( m_vOrigin[nDim1] - w + 35 / m_fScale, m_vOrigin[nDim2] + h - 20 / m_fScale );
1946 GlobalOpenGL().drawString( ViewType_getTitle( m_viewType ) );
1949 XYWnd::XY_DrawAxis();
1951 // show current work zone?
1952 // the work zone is used to place dropped points and brushes
1953 if ( g_xywindow_globals_private.d_show_work ) {
1954 glColor4f( 1.0f, 0.0f, 0.0f, 1.0f );
1955 glBegin( GL_LINES );
1956 glVertex2f( xb, Select_getWorkZone().d_work_min[nDim2] );
1957 glVertex2f( xe, Select_getWorkZone().d_work_min[nDim2] );
1958 glVertex2f( xb, Select_getWorkZone().d_work_max[nDim2] );
1959 glVertex2f( xe, Select_getWorkZone().d_work_max[nDim2] );
1960 glVertex2f( Select_getWorkZone().d_work_min[nDim1], yb );
1961 glVertex2f( Select_getWorkZone().d_work_min[nDim1], ye );
1962 glVertex2f( Select_getWorkZone().d_work_max[nDim1], yb );
1963 glVertex2f( Select_getWorkZone().d_work_max[nDim1], ye );
1973 void XYWnd::XY_DrawBlockGrid(){
1974 if ( Map_FindWorldspawn( g_map ) == 0 ) {
1977 const char *value = Node_getEntity( *Map_GetWorldspawn( g_map ) )->getKeyValue( "_blocksize" );
1978 if ( strlen( value ) ) {
1979 sscanf( value, "%i", &g_xywindow_globals_private.blockSize );
1982 if ( !g_xywindow_globals_private.blockSize || g_xywindow_globals_private.blockSize > 65536 || g_xywindow_globals_private.blockSize < 1024 ) {
1983 // don't use custom blocksize if it is less than the default, or greater than the maximum world coordinate
1984 g_xywindow_globals_private.blockSize = 1024;
1987 float x, y, xb, xe, yb, ye;
1991 glDisable( GL_TEXTURE_2D );
1992 glDisable( GL_TEXTURE_1D );
1993 glDisable( GL_DEPTH_TEST );
1994 glDisable( GL_BLEND );
1996 w = ( m_nWidth / 2 / m_fScale );
1997 h = ( m_nHeight / 2 / m_fScale );
1999 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
2000 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
2002 xb = m_vOrigin[nDim1] - w;
2003 if ( xb < region_mins[nDim1] ) {
2004 xb = region_mins[nDim1];
2006 xb = static_cast<float>( g_xywindow_globals_private.blockSize * floor( xb / g_xywindow_globals_private.blockSize ) );
2008 xe = m_vOrigin[nDim1] + w;
2009 if ( xe > region_maxs[nDim1] ) {
2010 xe = region_maxs[nDim1];
2012 xe = static_cast<float>( g_xywindow_globals_private.blockSize * ceil( xe / g_xywindow_globals_private.blockSize ) );
2014 yb = m_vOrigin[nDim2] - h;
2015 if ( yb < region_mins[nDim2] ) {
2016 yb = region_mins[nDim2];
2018 yb = static_cast<float>( g_xywindow_globals_private.blockSize * floor( yb / g_xywindow_globals_private.blockSize ) );
2020 ye = m_vOrigin[nDim2] + h;
2021 if ( ye > region_maxs[nDim2] ) {
2022 ye = region_maxs[nDim2];
2024 ye = static_cast<float>( g_xywindow_globals_private.blockSize * ceil( ye / g_xywindow_globals_private.blockSize ) );
2026 // draw major blocks
2028 glColor3fv( vector3_to_array( g_xywindow_globals.color_gridblock ) );
2031 glBegin( GL_LINES );
2033 for ( x = xb ; x <= xe ; x += g_xywindow_globals_private.blockSize )
2035 glVertex2f( x, yb );
2036 glVertex2f( x, ye );
2039 if ( m_viewType == XY ) {
2040 for ( y = yb ; y <= ye ; y += g_xywindow_globals_private.blockSize )
2042 glVertex2f( xb, y );
2043 glVertex2f( xe, y );
2050 // draw coordinate text if needed
2052 if ( m_viewType == XY && m_fScale > .1 ) {
2053 for ( x = xb ; x < xe ; x += g_xywindow_globals_private.blockSize )
2054 for ( y = yb ; y < ye ; y += g_xywindow_globals_private.blockSize )
2056 glRasterPos2f( x + ( g_xywindow_globals_private.blockSize / 2 ), y + ( g_xywindow_globals_private.blockSize / 2 ) );
2057 sprintf( text, "%i,%i",(int)floor( x / g_xywindow_globals_private.blockSize ), (int)floor( y / g_xywindow_globals_private.blockSize ) );
2058 GlobalOpenGL().drawString( text );
2062 glColor4f( 0, 0, 0, 0 );
2065 void XYWnd::DrawCameraIcon( const Vector3& origin, const Vector3& angles ){
2066 Cam.fov = 48 / m_fScale;
2067 Cam.box = 16 / m_fScale;
2068 // globalOutputStream() << "pitch " << angles[CAMERA_PITCH] << " yaw " << angles[CAMERA_YAW] << "\n";
2070 if ( m_viewType == XY ) {
2073 Cam.a = degrees_to_radians( angles[CAMERA_YAW] );
2075 else if ( m_viewType == YZ ) {
2078 Cam.a = degrees_to_radians( ( angles[CAMERA_YAW] > 180 ) ? ( 180.0f - angles[CAMERA_PITCH] ) : angles[CAMERA_PITCH] );
2084 Cam.a = degrees_to_radians( ( angles[CAMERA_YAW] < 270 && angles[CAMERA_YAW] > 90 ) ? ( 180.0f - angles[CAMERA_PITCH] ) : angles[CAMERA_PITCH] );
2087 //glColor3f( 0.0, 0.0, 1.0 );
2088 glColor3f( 1.0, 1.0, 1.0 );
2089 glBegin( GL_LINE_STRIP );
2090 glVertex3f( Cam.x - Cam.box,Cam.y,0 );
2091 glVertex3f( Cam.x,Cam.y + ( Cam.box / 2 ),0 );
2092 glVertex3f( Cam.x + Cam.box,Cam.y,0 );
2093 glVertex3f( Cam.x,Cam.y - ( Cam.box / 2 ),0 );
2094 glVertex3f( Cam.x - Cam.box,Cam.y,0 );
2095 glVertex3f( Cam.x + Cam.box,Cam.y,0 );
2098 glBegin( GL_LINE_STRIP );
2099 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 );
2100 glVertex3f( Cam.x, Cam.y, 0 );
2101 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 );
2106 void XYWnd::UpdateCameraIcon( void ){
2107 if ( glwidget_make_current( m_gl_widget ) != FALSE ) {
2108 if ( Map_Valid( g_map ) && ScreenUpdates_Enabled() ) {
2109 GlobalOpenGL_debugAssertNoErrors();
2110 glDrawBuffer( GL_FRONT );
2113 glViewport( 0, 0, m_nWidth, m_nHeight );
2115 glMatrixMode( GL_PROJECTION );
2116 glLoadMatrixf( reinterpret_cast<const float*>( &m_projection ) );
2118 glMatrixMode( GL_MODELVIEW );
2120 glScalef( m_fScale, m_fScale, 1 );
2121 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
2122 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
2123 glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 );
2125 glDisable( GL_LINE_STIPPLE );
2126 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2127 glDisableClientState( GL_NORMAL_ARRAY );
2128 glDisableClientState( GL_COLOR_ARRAY );
2129 glDisable( GL_TEXTURE_2D );
2130 glDisable( GL_LIGHTING );
2131 glDisable( GL_COLOR_MATERIAL );
2132 glDisable( GL_DEPTH_TEST );
2133 glDisable( GL_TEXTURE_1D );
2135 glEnable( GL_BLEND );
2136 glBlendFunc( GL_ONE_MINUS_DST_COLOR, GL_ZERO );
2138 //glColor3f( 0.0, 0.0, 1.0 );
2139 glColor3f( 1.0, 1.0, 1.0 );
2140 glBegin( GL_LINE_STRIP );
2141 glVertex3f( Cam.x - Cam.box,Cam.y,0 );
2142 glVertex3f( Cam.x,Cam.y + ( Cam.box / 2 ),0 );
2143 glVertex3f( Cam.x + Cam.box,Cam.y,0 );
2144 glVertex3f( Cam.x,Cam.y - ( Cam.box / 2 ),0 );
2145 glVertex3f( Cam.x - Cam.box,Cam.y,0 );
2146 glVertex3f( Cam.x + Cam.box,Cam.y,0 );
2149 glBegin( GL_LINE_STRIP );
2150 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 );
2151 glVertex3f( Cam.x, Cam.y, 0 );
2152 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 );
2155 XYWnd::DrawCameraIcon( Camera_getOrigin( *g_pParentWnd->GetCamWnd() ), Camera_getAngles( *g_pParentWnd->GetCamWnd() ) );
2157 glDisable( GL_BLEND );
2158 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
2161 glDrawBuffer( GL_BACK );
2162 GlobalOpenGL_debugAssertNoErrors();
2163 glwidget_make_current( m_gl_widget );
2169 float Betwixt( float f1, float f2 ){
2171 return f2 + ( ( f1 - f2 ) / 2 );
2174 return f1 + ( ( f2 - f1 ) / 2 );
2179 // can be greatly simplified but per usual i am in a hurry
2180 // which is not an excuse, just a fact
2181 void XYWnd::PaintSizeInfo( int nDim1, int nDim2, Vector3& vMinBounds, Vector3& vMaxBounds ){
2182 if ( vector3_equal( vMinBounds, vMaxBounds ) ) {
2185 const char* g_pDimStrings[] = {"x:", "y:", "z:"};
2186 typedef const char* OrgStrings[2];
2187 const OrgStrings g_pOrgStrings[] = { { "x:", "y:", }, { "x:", "z:", }, { "y:", "z:", } };
2189 Vector3 vSize( vector3_subtracted( vMaxBounds, vMinBounds ) );
2191 glColor3f( g_xywindow_globals.color_selbrushes[0] * .65f,
2192 g_xywindow_globals.color_selbrushes[1] * .65f,
2193 g_xywindow_globals.color_selbrushes[2] * .65f );
2195 StringOutputStream dimensions( 16 );
2197 if ( m_viewType == XY ) {
2198 glBegin( GL_LINES );
2200 glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f );
2201 glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
2203 glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
2204 glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
2206 glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f );
2207 glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
2210 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2], 0.0f );
2211 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f );
2213 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f );
2214 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f );
2216 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2], 0.0f );
2217 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f );
2221 glRasterPos3f( Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), vMinBounds[nDim2] - 20.0f / m_fScale, 0.0f );
2222 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
2223 GlobalOpenGL().drawString( dimensions.c_str() );
2226 glRasterPos3f( vMaxBounds[nDim1] + 16.0f / m_fScale, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ), 0.0f );
2227 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
2228 GlobalOpenGL().drawString( dimensions.c_str() );
2231 glRasterPos3f( vMinBounds[nDim1] + 4, vMaxBounds[nDim2] + 8 / m_fScale, 0.0f );
2232 dimensions << "(" << g_pOrgStrings[0][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[0][1] << vMaxBounds[nDim2] << ")";
2233 GlobalOpenGL().drawString( dimensions.c_str() );
2235 else if ( m_viewType == XZ ) {
2236 glBegin( GL_LINES );
2238 glVertex3f( vMinBounds[nDim1], 0, vMinBounds[nDim2] - 6.0f / m_fScale );
2239 glVertex3f( vMinBounds[nDim1], 0, vMinBounds[nDim2] - 10.0f / m_fScale );
2241 glVertex3f( vMinBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale );
2242 glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale );
2244 glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 6.0f / m_fScale );
2245 glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale );
2248 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, 0,vMinBounds[nDim2] );
2249 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMinBounds[nDim2] );
2251 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMinBounds[nDim2] );
2252 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMaxBounds[nDim2] );
2254 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, 0,vMaxBounds[nDim2] );
2255 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMaxBounds[nDim2] );
2259 glRasterPos3f( Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), 0, vMinBounds[nDim2] - 20.0f / m_fScale );
2260 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
2261 GlobalOpenGL().drawString( dimensions.c_str() );
2264 glRasterPos3f( vMaxBounds[nDim1] + 16.0f / m_fScale, 0, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ) );
2265 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
2266 GlobalOpenGL().drawString( dimensions.c_str() );
2269 glRasterPos3f( vMinBounds[nDim1] + 4, 0, vMaxBounds[nDim2] + 8 / m_fScale );
2270 dimensions << "(" << g_pOrgStrings[1][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[1][1] << vMaxBounds[nDim2] << ")";
2271 GlobalOpenGL().drawString( dimensions.c_str() );
2275 glBegin( GL_LINES );
2277 glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale );
2278 glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2280 glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2281 glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2283 glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale );
2284 glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2287 glVertex3f( 0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2] );
2288 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2] );
2290 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2] );
2291 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2] );
2293 glVertex3f( 0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2] );
2294 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2] );
2298 glRasterPos3f( 0, Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), vMinBounds[nDim2] - 20.0f / m_fScale );
2299 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
2300 GlobalOpenGL().drawString( dimensions.c_str() );
2303 glRasterPos3f( 0, vMaxBounds[nDim1] + 16.0f / m_fScale, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ) );
2304 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
2305 GlobalOpenGL().drawString( dimensions.c_str() );
2308 glRasterPos3f( 0, vMinBounds[nDim1] + 4.0f, vMaxBounds[nDim2] + 8 / m_fScale );
2309 dimensions << "(" << g_pOrgStrings[2][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[2][1] << vMaxBounds[nDim2] << ")";
2310 GlobalOpenGL().drawString( dimensions.c_str() );
2314 class XYRenderer : public Renderer
2322 unsigned int m_highlight;
2326 XYRenderer( RenderStateFlags globalstate, Shader* selected ) :
2327 m_globalstate( globalstate ),
2328 m_state_selected( selected ){
2329 ASSERT_NOTNULL( selected );
2330 m_state_stack.push_back( state_type() );
2333 void SetState( Shader* state, EStyle style ){
2334 ASSERT_NOTNULL( state );
2335 if ( style == eWireframeOnly ) {
2336 m_state_stack.back().m_state = state;
2339 const EStyle getStyle() const {
2340 return eWireframeOnly;
2343 m_state_stack.push_back( m_state_stack.back() );
2346 ASSERT_MESSAGE( !m_state_stack.empty(), "popping empty stack" );
2347 m_state_stack.pop_back();
2349 void Highlight( EHighlightMode mode, bool bEnable = true ){
2351 ? m_state_stack.back().m_highlight |= mode
2352 : m_state_stack.back().m_highlight &= ~mode;
2354 void addRenderable( const OpenGLRenderable& renderable, const Matrix4& localToWorld ){
2355 if ( m_state_stack.back().m_highlight & ePrimitive ) {
2356 m_state_selected->addRenderable( renderable, localToWorld );
2360 m_state_stack.back().m_state->addRenderable( renderable, localToWorld );
2364 void render( const Matrix4& modelview, const Matrix4& projection ){
2365 GlobalShaderCache().render( m_globalstate, modelview, projection );
2368 std::vector<state_type> m_state_stack;
2369 RenderStateFlags m_globalstate;
2370 Shader* m_state_selected;
2373 void XYWnd::updateProjection(){
2374 m_projection[0] = 1.0f / static_cast<float>( m_nWidth / 2 );
2375 m_projection[5] = 1.0f / static_cast<float>( m_nHeight / 2 );
2376 m_projection[10] = 1.0f / ( g_MaxWorldCoord * m_fScale );
2378 m_projection[12] = 0.0f;
2379 m_projection[13] = 0.0f;
2380 m_projection[14] = -1.0f;
2392 m_projection[11] = 0.0f;
2394 m_projection[15] = 1.0f;
2396 m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight );
2399 // note: modelview matrix must have a uniform scale, otherwise strange things happen when rendering the rotation manipulator.
2400 void XYWnd::updateModelview(){
2401 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
2402 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
2405 m_modelview[12] = -m_vOrigin[nDim1] * m_fScale;
2406 m_modelview[13] = -m_vOrigin[nDim2] * m_fScale;
2407 m_modelview[14] = g_MaxWorldCoord * m_fScale;
2410 switch ( m_viewType )
2413 m_modelview[0] = m_fScale;
2418 m_modelview[5] = m_fScale;
2423 m_modelview[10] = -m_fScale;
2426 m_modelview[0] = m_fScale;
2432 m_modelview[6] = m_fScale;
2435 m_modelview[9] = m_fScale;
2436 m_modelview[10] = 0;
2441 m_modelview[2] = -m_fScale;
2443 m_modelview[4] = m_fScale;
2448 m_modelview[9] = m_fScale;
2449 m_modelview[10] = 0;
2453 m_modelview[3] = m_modelview[7] = m_modelview[11] = 0;
2454 m_modelview[15] = 1;
2456 m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight );
2465 //#define DBG_SCENEDUMP
2467 void XYWnd::XY_Draw(){
2471 glViewport( 0, 0, m_nWidth, m_nHeight );
2472 glClearColor( g_xywindow_globals.color_gridback[0],
2473 g_xywindow_globals.color_gridback[1],
2474 g_xywindow_globals.color_gridback[2],0 );
2476 glClear( GL_COLOR_BUFFER_BIT );
2482 glMatrixMode( GL_PROJECTION );
2483 glLoadMatrixf( reinterpret_cast<const float*>( &m_projection ) );
2485 glMatrixMode( GL_MODELVIEW );
2487 glScalef( m_fScale, m_fScale, 1 );
2488 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
2489 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
2490 glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 );
2492 glDisable( GL_LINE_STIPPLE );
2494 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2495 glDisableClientState( GL_NORMAL_ARRAY );
2496 glDisableClientState( GL_COLOR_ARRAY );
2497 glDisable( GL_TEXTURE_2D );
2498 glDisable( GL_LIGHTING );
2499 glDisable( GL_COLOR_MATERIAL );
2500 glDisable( GL_DEPTH_TEST );
2502 if ( m_backgroundActivated ) {
2503 XY_DrawBackground();
2507 if ( g_xywindow_globals_private.show_blocks ) {
2511 glLoadMatrixf( reinterpret_cast<const float*>( &m_modelview ) );
2513 unsigned int globalstate = RENDER_COLOURARRAY | RENDER_COLOURWRITE | RENDER_POLYGONSMOOTH | RENDER_LINESMOOTH;
2514 if ( !g_xywindow_globals.m_bNoStipple ) {
2515 globalstate |= RENDER_LINESTIPPLE;
2519 XYRenderer renderer( globalstate, m_state_selected );
2521 Scene_Render( renderer, m_view );
2523 GlobalOpenGL_debugAssertNoErrors();
2524 renderer.render( m_modelview, m_projection );
2525 GlobalOpenGL_debugAssertNoErrors();
2528 glDepthMask( GL_FALSE );
2530 GlobalOpenGL_debugAssertNoErrors();
2532 glLoadMatrixf( reinterpret_cast<const float*>( &m_modelview ) );
2534 GlobalOpenGL_debugAssertNoErrors();
2535 glDisable( GL_LINE_STIPPLE );
2536 GlobalOpenGL_debugAssertNoErrors();
2538 GlobalOpenGL_debugAssertNoErrors();
2539 if ( GlobalOpenGL().GL_1_3() ) {
2540 glActiveTexture( GL_TEXTURE0 );
2541 glClientActiveTexture( GL_TEXTURE0 );
2543 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2544 GlobalOpenGL_debugAssertNoErrors();
2545 glDisableClientState( GL_NORMAL_ARRAY );
2546 GlobalOpenGL_debugAssertNoErrors();
2547 glDisableClientState( GL_COLOR_ARRAY );
2548 GlobalOpenGL_debugAssertNoErrors();
2549 glDisable( GL_TEXTURE_2D );
2550 GlobalOpenGL_debugAssertNoErrors();
2551 glDisable( GL_LIGHTING );
2552 GlobalOpenGL_debugAssertNoErrors();
2553 glDisable( GL_COLOR_MATERIAL );
2554 GlobalOpenGL_debugAssertNoErrors();
2556 GlobalOpenGL_debugAssertNoErrors();
2560 if ( g_xywindow_globals_private.m_bSizePaint && GlobalSelectionSystem().countSelected() != 0 ) {
2562 Select_GetBounds( min, max );
2563 PaintSizeInfo( nDim1, nDim2, min, max );
2566 if ( g_bCrossHairs ) {
2567 glColor4f( 0.2f, 0.9f, 0.2f, 0.8f );
2568 glBegin( GL_LINES );
2569 if ( m_viewType == XY ) {
2570 glVertex2f( 2.0f * g_MinWorldCoord, m_mousePosition[1] );
2571 glVertex2f( 2.0f * g_MaxWorldCoord, m_mousePosition[1] );
2572 glVertex2f( m_mousePosition[0], 2.0f * g_MinWorldCoord );
2573 glVertex2f( m_mousePosition[0], 2.0f * g_MaxWorldCoord );
2575 else if ( m_viewType == YZ ) {
2576 glVertex3f( m_mousePosition[0], 2.0f * g_MinWorldCoord, m_mousePosition[2] );
2577 glVertex3f( m_mousePosition[0], 2.0f * g_MaxWorldCoord, m_mousePosition[2] );
2578 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MinWorldCoord );
2579 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MaxWorldCoord );
2583 glVertex3f( 2.0f * g_MinWorldCoord, m_mousePosition[1], m_mousePosition[2] );
2584 glVertex3f( 2.0f * g_MaxWorldCoord, m_mousePosition[1], m_mousePosition[2] );
2585 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MinWorldCoord );
2586 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MaxWorldCoord );
2592 GlobalClipPoints_Draw( m_fScale );
2595 GlobalOpenGL_debugAssertNoErrors();
2599 glScalef( m_fScale, m_fScale, 1 );
2600 glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 );
2602 glEnable( GL_BLEND );
2603 glBlendFunc( GL_ONE_MINUS_DST_COLOR, GL_ZERO );
2604 DrawCameraIcon( Camera_getOrigin( *g_pParentWnd->GetCamWnd() ), Camera_getAngles( *g_pParentWnd->GetCamWnd() ) );
2605 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
2606 glDisable( GL_BLEND );
2608 Feedback_draw2D( m_viewType );
2610 if ( g_xywindow_globals_private.show_outline ) {
2612 glMatrixMode( GL_PROJECTION );
2614 glOrtho( 0, m_nWidth, 0, m_nHeight, 0, 1 );
2616 glMatrixMode( GL_MODELVIEW );
2619 // four view mode doesn't colorize
2620 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) {
2621 glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) );
2625 switch ( m_viewType )
2628 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorX ) );
2631 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorY ) );
2634 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorZ ) );
2638 glBegin( GL_LINE_LOOP );
2639 glVertex2f( 0.5, 0.5 );
2640 glVertex2f( m_nWidth - 0.5, 1 );
2641 glVertex2f( m_nWidth - 0.5, m_nHeight - 0.5 );
2642 glVertex2f( 0.5, m_nHeight - 0.5 );
2647 GlobalOpenGL_debugAssertNoErrors();
2652 void XYWnd_MouseToPoint( XYWnd* xywnd, int x, int y, Vector3& point ){
2653 xywnd->XY_ToPoint( x, y, point );
2654 xywnd->XY_SnapToGrid( point );
2656 int nDim = ( xywnd->GetViewType() == XY ) ? 2 : ( xywnd->GetViewType() == YZ ) ? 0 : 1;
2657 float fWorkMid = float_mid( Select_getWorkZone().d_work_min[nDim], Select_getWorkZone().d_work_max[nDim] );
2658 point[nDim] = float_snapped( fWorkMid, GetGridSize() );
2661 void XYWnd::OnEntityCreate( const char* item ){
2662 StringOutputStream command;
2663 command << "entityCreate -class " << item;
2664 UndoableCommand undo( command.c_str() );
2666 XYWnd_MouseToPoint( this, m_entityCreate_x, m_entityCreate_y, point );
2667 Entity_createFromSelection( item, point );
2672 void GetFocusPosition( Vector3& position ){
2673 if ( GlobalSelectionSystem().countSelected() != 0 ) {
2674 Select_GetMid( position );
2678 position = Camera_getOrigin( *g_pParentWnd->GetCamWnd() );
2682 void XYWnd_Focus( XYWnd* xywnd ){
2684 GetFocusPosition( position );
2685 xywnd->PositionView( position );
2688 void XY_Split_Focus(){
2690 GetFocusPosition( position );
2691 if ( g_pParentWnd->GetXYWnd() ) {
2692 g_pParentWnd->GetXYWnd()->PositionView( position );
2694 if ( g_pParentWnd->GetXZWnd() ) {
2695 g_pParentWnd->GetXZWnd()->PositionView( position );
2697 if ( g_pParentWnd->GetYZWnd() ) {
2698 g_pParentWnd->GetYZWnd()->PositionView( position );
2703 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) {
2704 // cannot do this in a split window
2705 // do something else that the user may want here
2710 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2711 XYWnd_Focus( xywnd );
2714 void XY_TopFrontSide( VIEWTYPE viewtype ){
2715 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) {
2716 // cannot do this in a split window
2717 // do something else that the user may want here
2721 XYWnd* xywnd = g_pParentWnd->CurrentStyle() == MainFrame::eFloating ? g_pParentWnd->ActiveXY() : g_pParentWnd->GetXYWnd();
2722 xywnd->SetViewType( viewtype );
2723 XYWnd_Focus( xywnd );
2727 XY_TopFrontSide( XY );
2731 XY_TopFrontSide( XZ );
2735 XY_TopFrontSide( YZ );
2738 void XY_NextView( XYWnd* xywnd ){
2739 if ( xywnd->GetViewType() == XY ) {
2740 xywnd->SetViewType( XZ );
2742 else if ( xywnd->GetViewType() == XZ ) {
2743 xywnd->SetViewType( YZ );
2746 xywnd->SetViewType( XY );
2748 XYWnd_Focus( xywnd );
2752 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) {
2753 // cannot do this in a split window
2754 // do something else that the user may want here
2758 XYWnd* xywnd = g_pParentWnd->CurrentStyle() == MainFrame::eFloating ? g_pParentWnd->ActiveXY() : g_pParentWnd->GetXYWnd();
2759 XY_NextView( xywnd );
2763 if ( g_pParentWnd->GetXYWnd() ) {
2764 g_pParentWnd->GetXYWnd()->SetScale( 1 );
2766 if ( g_pParentWnd->GetXZWnd() ) {
2767 g_pParentWnd->GetXZWnd()->SetScale( 1 );
2769 if ( g_pParentWnd->GetYZWnd() ) {
2770 g_pParentWnd->GetYZWnd()->SetScale( 1 );
2775 g_pParentWnd->ActiveXY()->ZoomIn();
2778 // NOTE: the zoom out factor is 4/5, we could think about customizing it
2779 // we don't go below a zoom factor corresponding to 10% of the max world size
2780 // (this has to be computed against the window size)
2782 g_pParentWnd->ActiveXY()->ZoomOut();
2787 ToggleShown g_xy_top_shown( true );
2789 void XY_Top_Shown_Construct( GtkWindow* parent ){
2790 g_xy_top_shown.connect( GTK_WIDGET( parent ) );
2793 ToggleShown g_yz_side_shown( false );
2795 void YZ_Side_Shown_Construct( GtkWindow* parent ){
2796 g_yz_side_shown.connect( GTK_WIDGET( parent ) );
2799 ToggleShown g_xz_front_shown( false );
2801 void XZ_Front_Shown_Construct( GtkWindow* parent ){
2802 g_xz_front_shown.connect( GTK_WIDGET( parent ) );
2806 class EntityClassMenu : public ModuleObserver
2808 std::size_t m_unrealised;
2810 EntityClassMenu() : m_unrealised( 1 ){
2813 if ( --m_unrealised == 0 ) {
2817 if ( ++m_unrealised == 1 ) {
2818 if ( XYWnd::m_mnuDrop != 0 ) {
2819 gtk_widget_destroy( GTK_WIDGET( XYWnd::m_mnuDrop ) );
2820 XYWnd::m_mnuDrop = 0;
2826 EntityClassMenu g_EntityClassMenu;
2831 void ShowNamesExport( const BoolImportCallback& importer ){
2832 importer( GlobalEntityCreator().getShowNames() );
2834 typedef FreeCaller1<const BoolImportCallback&, ShowNamesExport> ShowNamesExportCaller;
2835 ShowNamesExportCaller g_show_names_caller;
2836 ToggleItem g_show_names( g_show_names_caller );
2837 void ShowNamesToggle(){
2838 GlobalEntityCreator().setShowNames( !GlobalEntityCreator().getShowNames() );
2839 g_show_names.update();
2840 XY_UpdateAllWindows();
2843 void ShowAnglesExport( const BoolImportCallback& importer ){
2844 importer( GlobalEntityCreator().getShowAngles() );
2846 typedef FreeCaller1<const BoolImportCallback&, ShowAnglesExport> ShowAnglesExportCaller;
2847 ShowAnglesExportCaller g_show_angles_caller;
2848 ToggleItem g_show_angles( g_show_angles_caller );
2849 void ShowAnglesToggle(){
2850 GlobalEntityCreator().setShowAngles( !GlobalEntityCreator().getShowAngles() );
2851 g_show_angles.update();
2852 XY_UpdateAllWindows();
2855 BoolExportCaller g_show_blocks_caller( g_xywindow_globals_private.show_blocks );
2856 ToggleItem g_show_blocks( g_show_blocks_caller );
2857 void ShowBlocksToggle(){
2858 g_xywindow_globals_private.show_blocks ^= 1;
2859 g_show_blocks.update();
2860 XY_UpdateAllWindows();
2863 BoolExportCaller g_show_coordinates_caller( g_xywindow_globals_private.show_coordinates );
2864 ToggleItem g_show_coordinates( g_show_coordinates_caller );
2865 void ShowCoordinatesToggle(){
2866 g_xywindow_globals_private.show_coordinates ^= 1;
2867 g_show_coordinates.update();
2868 XY_UpdateAllWindows();
2871 BoolExportCaller g_show_outline_caller( g_xywindow_globals_private.show_outline );
2872 ToggleItem g_show_outline( g_show_outline_caller );
2873 void ShowOutlineToggle(){
2874 g_xywindow_globals_private.show_outline ^= 1;
2875 g_show_outline.update();
2876 XY_UpdateAllWindows();
2879 BoolExportCaller g_show_axes_caller( g_xywindow_globals_private.show_axis );
2880 ToggleItem g_show_axes( g_show_axes_caller );
2881 void ShowAxesToggle(){
2882 g_xywindow_globals_private.show_axis ^= 1;
2883 g_show_axes.update();
2884 XY_UpdateAllWindows();
2888 BoolExportCaller g_show_workzone_caller( g_xywindow_globals_private.d_show_work );
2889 ToggleItem g_show_workzone( g_show_workzone_caller );
2890 void ShowWorkzoneToggle(){
2891 g_xywindow_globals_private.d_show_work ^= 1;
2892 g_show_workzone.update();
2893 XY_UpdateAllWindows();
2897 void ShowAxesToggle(){
2898 g_xywindow_globals_private.show_axis ^= 1;
2899 XY_UpdateAllWindows();
2901 typedef FreeCaller<ShowAxesToggle> ShowAxesToggleCaller;
2902 void ShowAxesExport( const BoolImportCallback& importer ){
2903 importer( g_xywindow_globals_private.show_axis );
2905 typedef FreeCaller1<const BoolImportCallback&, ShowAxesExport> ShowAxesExportCaller;
2907 ShowAxesExportCaller g_show_axes_caller;
2908 BoolExportCallback g_show_axes_callback( g_show_axes_caller );
2909 ToggleItem g_show_axes( g_show_axes_callback );
2913 BoolExportCaller g_texdef_movelock_caller( g_brush_texturelock_enabled );
2914 ToggleItem g_texdef_movelock_item( g_texdef_movelock_caller );
2916 void Texdef_ToggleMoveLock(){
2917 g_brush_texturelock_enabled = !g_brush_texturelock_enabled;
2918 g_texdef_movelock_item.update();
2922 BoolExportCaller g_show_size_caller( g_xywindow_globals_private.m_bSizePaint );
2923 ToggleItem g_show_size_item( g_show_size_caller );
2924 void ToggleShowSizeInfo(){
2925 g_xywindow_globals_private.m_bSizePaint = !g_xywindow_globals_private.m_bSizePaint;
2926 g_show_size_item.update();
2927 XY_UpdateAllWindows();
2930 BoolExportCaller g_show_crosshair_caller( g_bCrossHairs );
2931 ToggleItem g_show_crosshair_item( g_show_crosshair_caller );
2932 void ToggleShowCrosshair(){
2934 g_show_crosshair_item.update();
2935 XY_UpdateAllWindows();
2938 BoolExportCaller g_show_grid_caller( g_xywindow_globals_private.d_showgrid );
2939 ToggleItem g_show_grid_item( g_show_grid_caller );
2940 void ToggleShowGrid(){
2941 g_xywindow_globals_private.d_showgrid = !g_xywindow_globals_private.d_showgrid;
2942 g_show_grid_item.update();
2943 XY_UpdateAllWindows();
2947 void XYShow_registerCommands(){
2948 GlobalToggles_insert( "ToggleSizePaint", FreeCaller<ToggleShowSizeInfo>(), ToggleItem::AddCallbackCaller( g_show_size_item ), Accelerator( 'J' ) );
2949 GlobalToggles_insert( "ToggleCrosshairs", FreeCaller<ToggleShowCrosshair>(), ToggleItem::AddCallbackCaller( g_show_crosshair_item ), Accelerator( 'X', (GdkModifierType)GDK_SHIFT_MASK ) );
2950 GlobalToggles_insert( "ToggleGrid", FreeCaller<ToggleShowGrid>(), ToggleItem::AddCallbackCaller( g_show_grid_item ), Accelerator( '0' ) );
2952 GlobalToggles_insert( "ShowAngles", FreeCaller<ShowAnglesToggle>(), ToggleItem::AddCallbackCaller( g_show_angles ) );
2953 GlobalToggles_insert( "ShowNames", FreeCaller<ShowNamesToggle>(), ToggleItem::AddCallbackCaller( g_show_names ) );
2954 GlobalToggles_insert( "ShowBlocks", FreeCaller<ShowBlocksToggle>(), ToggleItem::AddCallbackCaller( g_show_blocks ) );
2955 GlobalToggles_insert( "ShowCoordinates", FreeCaller<ShowCoordinatesToggle>(), ToggleItem::AddCallbackCaller( g_show_coordinates ) );
2956 GlobalToggles_insert( "ShowWindowOutline", FreeCaller<ShowOutlineToggle>(), ToggleItem::AddCallbackCaller( g_show_outline ) );
2957 GlobalToggles_insert( "ShowAxes", FreeCaller<ShowAxesToggle>(), ToggleItem::AddCallbackCaller( g_show_axes ) );
2958 GlobalToggles_insert( "ShowWorkzone", FreeCaller<ShowWorkzoneToggle>(), ToggleItem::AddCallbackCaller( g_show_workzone ) );
2961 void XYWnd_registerShortcuts(){
2962 command_connect_accelerator( "ToggleCrosshairs" );
2963 command_connect_accelerator( "ToggleSizePaint" );
2968 void Orthographic_constructPreferences( PreferencesPage& page ){
2969 page.appendCheckBox( "", "Solid selection boxes ( no stipple )", g_xywindow_globals.m_bNoStipple );
2970 //page.appendCheckBox( "", "Display size info", g_xywindow_globals_private.m_bSizePaint );
2971 page.appendCheckBox( "", "Chase mouse during drags", g_xywindow_globals_private.m_bChaseMouse );
2972 // page.appendCheckBox( "", "Update views on camera move", g_xywindow_globals_private.m_bCamXYUpdate );
2974 void Orthographic_constructPage( PreferenceGroup& group ){
2975 PreferencesPage page( group.createPage( "Orthographic", "Orthographic View Preferences" ) );
2976 Orthographic_constructPreferences( page );
2978 void Orthographic_registerPreferencesPage(){
2979 PreferencesDialog_addSettingsPage( FreeCaller1<PreferenceGroup&, Orthographic_constructPage>() );
2982 void Clipper_constructPreferences( PreferencesPage& page ){
2983 page.appendCheckBox( "", "Clipper tool uses caulk", g_clip_useCaulk );
2985 void Clipper_constructPage( PreferenceGroup& group ){
2986 PreferencesPage page( group.createPage( "Clipper", "Clipper Tool Settings" ) );
2987 Clipper_constructPreferences( page );
2989 void Clipper_registerPreferencesPage(){
2990 PreferencesDialog_addSettingsPage( FreeCaller1<PreferenceGroup&, Clipper_constructPage>() );
2994 #include "preferencesystem.h"
2995 #include "stringio.h"
3000 void ToggleShown_importBool( ToggleShown& self, bool value ){
3003 typedef ReferenceCaller1<ToggleShown, bool, ToggleShown_importBool> ToggleShownImportBoolCaller;
3004 void ToggleShown_exportBool( const ToggleShown& self, const BoolImportCallback& importer ){
3005 importer( self.active() );
3007 typedef ConstReferenceCaller1<ToggleShown, const BoolImportCallback&, ToggleShown_exportBool> ToggleShownExportBoolCaller;
3010 void XYWindow_Construct(){
3011 // GlobalCommands_insert( "ToggleCrosshairs", FreeCaller<ToggleShowCrosshair>(), Accelerator( 'X', (GdkModifierType)GDK_SHIFT_MASK ) );
3012 // GlobalCommands_insert( "ToggleSizePaint", FreeCaller<ToggleShowSizeInfo>(), Accelerator( 'J' ) );
3013 // GlobalCommands_insert( "ToggleGrid", FreeCaller<ToggleShowGrid>(), Accelerator( '0' ) );
3015 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 ) ) );
3016 GlobalToggles_insert( "ToggleSideView", ToggleShown::ToggleCaller( g_yz_side_shown ), ToggleItem::AddCallbackCaller( g_yz_side_shown.m_item ) );
3017 GlobalToggles_insert( "ToggleFrontView", ToggleShown::ToggleCaller( g_xz_front_shown ), ToggleItem::AddCallbackCaller( g_xz_front_shown.m_item ) );
3018 GlobalCommands_insert( "NextView", FreeCaller<XY_Next>(), Accelerator( GDK_Tab, (GdkModifierType)GDK_CONTROL_MASK ) );
3019 GlobalCommands_insert( "ZoomIn", FreeCaller<XY_ZoomIn>(), Accelerator( GDK_Delete ) );
3020 GlobalCommands_insert( "ZoomOut", FreeCaller<XY_ZoomOut>(), Accelerator( GDK_Insert ) );
3021 GlobalCommands_insert( "ViewTop", FreeCaller<XY_Top>(), Accelerator( GDK_KP_Home ) );
3022 GlobalCommands_insert( "ViewSide", FreeCaller<XY_Side>(), Accelerator( GDK_KP_Page_Down ) );
3023 GlobalCommands_insert( "ViewFront", FreeCaller<XY_Front>(), Accelerator( GDK_KP_End ) );
3024 GlobalCommands_insert( "Zoom100", FreeCaller<XY_Zoom100>() );
3025 GlobalCommands_insert( "CenterXYView", FreeCaller<XY_Focus>(), Accelerator( GDK_Tab, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
3027 GlobalPreferenceSystem().registerPreference( "ClipCaulk", BoolImportStringCaller( g_clip_useCaulk ), BoolExportStringCaller( g_clip_useCaulk ) );
3029 // GlobalPreferenceSystem().registerPreference( "NewRightClick", BoolImportStringCaller( g_xywindow_globals.m_bRightClick ), BoolExportStringCaller( g_xywindow_globals.m_bRightClick ) );
3030 GlobalPreferenceSystem().registerPreference( "ImprovedWheelZoom", BoolImportStringCaller( g_xywindow_globals.m_bImprovedWheelZoom ), BoolExportStringCaller( g_xywindow_globals.m_bImprovedWheelZoom ) );
3031 GlobalPreferenceSystem().registerPreference( "ChaseMouse", BoolImportStringCaller( g_xywindow_globals_private.m_bChaseMouse ), BoolExportStringCaller( g_xywindow_globals_private.m_bChaseMouse ) );
3032 GlobalPreferenceSystem().registerPreference( "SizePainting", BoolImportStringCaller( g_xywindow_globals_private.m_bSizePaint ), BoolExportStringCaller( g_xywindow_globals_private.m_bSizePaint ) );
3033 GlobalPreferenceSystem().registerPreference( "ShowCrosshair", BoolImportStringCaller( g_bCrossHairs ), BoolExportStringCaller( g_bCrossHairs ) );
3034 GlobalPreferenceSystem().registerPreference( "NoStipple", BoolImportStringCaller( g_xywindow_globals.m_bNoStipple ), BoolExportStringCaller( g_xywindow_globals.m_bNoStipple ) );
3035 GlobalPreferenceSystem().registerPreference( "SI_ShowCoords", BoolImportStringCaller( g_xywindow_globals_private.show_coordinates ), BoolExportStringCaller( g_xywindow_globals_private.show_coordinates ) );
3036 GlobalPreferenceSystem().registerPreference( "SI_ShowOutlines", BoolImportStringCaller( g_xywindow_globals_private.show_outline ), BoolExportStringCaller( g_xywindow_globals_private.show_outline ) );
3037 GlobalPreferenceSystem().registerPreference( "SI_ShowAxis", BoolImportStringCaller( g_xywindow_globals_private.show_axis ), BoolExportStringCaller( g_xywindow_globals_private.show_axis ) );
3038 // GlobalPreferenceSystem().registerPreference( "CamXYUpdate", BoolImportStringCaller( g_xywindow_globals_private.m_bCamXYUpdate ), BoolExportStringCaller( g_xywindow_globals_private.m_bCamXYUpdate ) );
3039 GlobalPreferenceSystem().registerPreference( "ShowWorkzone", BoolImportStringCaller( g_xywindow_globals_private.d_show_work ), BoolExportStringCaller( g_xywindow_globals_private.d_show_work ) );
3041 GlobalPreferenceSystem().registerPreference( "SI_AxisColors0", Vector3ImportStringCaller( g_xywindow_globals.AxisColorX ), Vector3ExportStringCaller( g_xywindow_globals.AxisColorX ) );
3042 GlobalPreferenceSystem().registerPreference( "SI_AxisColors1", Vector3ImportStringCaller( g_xywindow_globals.AxisColorY ), Vector3ExportStringCaller( g_xywindow_globals.AxisColorY ) );
3043 GlobalPreferenceSystem().registerPreference( "SI_AxisColors2", Vector3ImportStringCaller( g_xywindow_globals.AxisColorZ ), Vector3ExportStringCaller( g_xywindow_globals.AxisColorZ ) );
3044 GlobalPreferenceSystem().registerPreference( "SI_Colors1", Vector3ImportStringCaller( g_xywindow_globals.color_gridback ), Vector3ExportStringCaller( g_xywindow_globals.color_gridback ) );
3045 GlobalPreferenceSystem().registerPreference( "SI_Colors2", Vector3ImportStringCaller( g_xywindow_globals.color_gridminor ), Vector3ExportStringCaller( g_xywindow_globals.color_gridminor ) );
3046 GlobalPreferenceSystem().registerPreference( "SI_Colors3", Vector3ImportStringCaller( g_xywindow_globals.color_gridmajor ), Vector3ExportStringCaller( g_xywindow_globals.color_gridmajor ) );
3047 GlobalPreferenceSystem().registerPreference( "SI_Colors6", Vector3ImportStringCaller( g_xywindow_globals.color_gridblock ), Vector3ExportStringCaller( g_xywindow_globals.color_gridblock ) );
3048 GlobalPreferenceSystem().registerPreference( "SI_Colors7", Vector3ImportStringCaller( g_xywindow_globals.color_gridtext ), Vector3ExportStringCaller( g_xywindow_globals.color_gridtext ) );
3049 GlobalPreferenceSystem().registerPreference( "SI_Colors8", Vector3ImportStringCaller( g_xywindow_globals.color_brushes ), Vector3ExportStringCaller( g_xywindow_globals.color_brushes ) );
3050 GlobalPreferenceSystem().registerPreference( "SI_Colors9", Vector3ImportStringCaller( g_xywindow_globals.color_viewname ), Vector3ExportStringCaller( g_xywindow_globals.color_viewname ) );
3051 GlobalPreferenceSystem().registerPreference( "SI_Colors10", Vector3ImportStringCaller( g_xywindow_globals.color_clipper ), Vector3ExportStringCaller( g_xywindow_globals.color_clipper ) );
3052 GlobalPreferenceSystem().registerPreference( "SI_Colors11", Vector3ImportStringCaller( g_xywindow_globals.color_selbrushes ), Vector3ExportStringCaller( g_xywindow_globals.color_selbrushes ) );
3055 GlobalPreferenceSystem().registerPreference( "XZVIS", makeBoolStringImportCallback( ToggleShownImportBoolCaller( g_xz_front_shown ) ), makeBoolStringExportCallback( ToggleShownExportBoolCaller( g_xz_front_shown ) ) );
3056 GlobalPreferenceSystem().registerPreference( "YZVIS", makeBoolStringImportCallback( ToggleShownImportBoolCaller( g_yz_side_shown ) ), makeBoolStringExportCallback( ToggleShownExportBoolCaller( g_yz_side_shown ) ) );
3058 Orthographic_registerPreferencesPage();
3059 Clipper_registerPreferencesPage();
3061 XYWnd::captureStates();
3062 GlobalEntityClassManager().attach( g_EntityClassMenu );
3065 void XYWindow_Destroy(){
3066 GlobalEntityClassManager().detach( g_EntityClassMenu );
3067 XYWnd::releaseStates();