2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 // Leonardo Zide (leo@lokigames.com)
32 #include "debugging/debugging.h"
39 #include "ifilesystem.h"
42 #include "gtkutil/messagebox.h"
44 #include <uilib/uilib.h>
45 #include <gdk/gdkkeysyms.h>
47 #include "generic/callback.h"
48 #include "string/string.h"
49 #include "stream/stringstream.h"
52 #include "eclasslib.h"
54 #include "moduleobserver.h"
56 #include "gtkutil/menu.h"
57 #include "gtkutil/container.h"
58 #include "gtkutil/widget.h"
59 #include "gtkutil/glwidget.h"
60 #include "gtkutil/filechooser.h"
64 #include "brushmanip.h"
65 #include "selection.h"
67 #include "camwindow.h"
68 #include "texwindow.h"
69 #include "mainframe.h"
70 #include "preferences.h"
74 #include "windowobservers.h"
76 void LoadTextureRGBA( qtexture_t* q, unsigned char* pPixels, int nWidth, int nHeight );
79 extern bool g_brush_always_caulk;
85 Vector3 m_ptClip; // the 3d point
92 m_ptClip[0] = m_ptClip[1] = m_ptClip[2] = 0.0;
106 /*! Draw clip/path point with rasterized number label */
107 void Draw( int num, float scale );
108 /*! Draw clip/path point with rasterized string label */
109 void Draw( const char *label, float scale );
112 VIEWTYPE g_clip_viewtype;
113 bool g_bSwitch = true;
114 bool g_clip_useCaulk = false;
115 bool g_quick_clipper = false;
119 ClipPoint* g_pMovingClip = 0;
121 /* Drawing clip points */
122 void ClipPoint::Draw( int num, float scale ){
123 StringOutputStream label( 4 );
125 Draw( label.c_str(), scale );
128 void ClipPoint::Draw( const char *label, float scale ){
131 glColor3fv( vector3_to_array( g_xywindow_globals.color_clipper ) );
132 glBegin( GL_POINTS );
133 glVertex3fv( vector3_to_array( m_ptClip ) );
137 float offset = 2.0f / scale;
140 glRasterPos3f( m_ptClip[0] + offset, m_ptClip[1] + offset, m_ptClip[2] + offset );
141 glCallLists( GLsizei( strlen( label ) ), GL_UNSIGNED_BYTE, label );
144 float fDiff( float f1, float f2 ){
153 inline double ClipPoint_Intersect( const ClipPoint& clip, const Vector3& point, VIEWTYPE viewtype, float scale ){
154 int nDim1 = ( viewtype == YZ ) ? 1 : 0;
155 int nDim2 = ( viewtype == XY ) ? 1 : 2;
156 double screenDistanceSquared( vector2_length_squared( Vector2( fDiff( clip.m_ptClip[nDim1], point[nDim1] ) * scale, fDiff( clip.m_ptClip[nDim2], point[nDim2] ) * scale ) ) );
157 if ( screenDistanceSquared < 8 * 8 ) {
158 return screenDistanceSquared;
163 inline void ClipPoint_testSelect( ClipPoint& clip, const Vector3& point, VIEWTYPE viewtype, float scale, double& bestDistance, ClipPoint*& bestClip ){
165 double distance = ClipPoint_Intersect( clip, point, viewtype, scale );
166 if ( distance < bestDistance ) {
167 bestDistance = distance;
173 inline ClipPoint* GlobalClipPoints_Find( const Vector3& point, VIEWTYPE viewtype, float scale ){
174 double bestDistance = FLT_MAX;
175 ClipPoint* bestClip = 0;
176 ClipPoint_testSelect( g_Clip1, point, viewtype, scale, bestDistance, bestClip );
177 ClipPoint_testSelect( g_Clip2, point, viewtype, scale, bestDistance, bestClip );
178 ClipPoint_testSelect( g_Clip3, point, viewtype, scale, bestDistance, bestClip );
182 inline void GlobalClipPoints_Draw( float scale ){
184 if ( g_Clip1.Set() ) {
185 g_Clip1.Draw( 1, scale );
187 if ( g_Clip2.Set() ) {
188 g_Clip2.Draw( 2, scale );
190 if ( g_Clip3.Set() ) {
191 g_Clip3.Draw( 3, scale );
195 inline bool GlobalClipPoints_valid(){
196 return g_Clip1.Set() && g_Clip2.Set();
199 void PlanePointsFromClipPoints( Vector3 planepts[3], const AABB& bounds, int viewtype ){
200 ASSERT_MESSAGE( GlobalClipPoints_valid(), "clipper points not initialised" );
201 planepts[0] = g_Clip1.m_ptClip;
202 planepts[1] = g_Clip2.m_ptClip;
203 planepts[2] = g_Clip3.m_ptClip;
204 Vector3 maxs( vector3_added( bounds.origin, bounds.extents ) );
205 Vector3 mins( vector3_subtracted( bounds.origin, bounds.extents ) );
206 if ( !g_Clip3.Set() ) {
207 int n = ( viewtype == XY ) ? 2 : ( viewtype == YZ ) ? 0 : 1;
208 int x = ( n == 0 ) ? 1 : 0;
209 int y = ( n == 2 ) ? 1 : 2;
211 if ( n == 1 ) { // on viewtype XZ, flip clip points
212 planepts[0][n] = maxs[n];
213 planepts[1][n] = maxs[n];
214 planepts[2][x] = g_Clip1.m_ptClip[x];
215 planepts[2][y] = g_Clip1.m_ptClip[y];
216 planepts[2][n] = mins[n];
220 planepts[0][n] = mins[n];
221 planepts[1][n] = mins[n];
222 planepts[2][x] = g_Clip1.m_ptClip[x];
223 planepts[2][y] = g_Clip1.m_ptClip[y];
224 planepts[2][n] = maxs[n];
231 if ( !GlobalClipPoints_valid() ) {
232 planepts[0] = Vector3( 0, 0, 0 );
233 planepts[1] = Vector3( 0, 0, 0 );
234 planepts[2] = Vector3( 0, 0, 0 );
235 Scene_BrushSetClipPlane( GlobalSceneGraph(), Plane3( 0, 0, 0, 0 ) );
239 AABB bounds( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) );
240 PlanePointsFromClipPoints( planepts, bounds, g_clip_viewtype );
242 std::swap( planepts[0], planepts[1] );
244 Scene_BrushSetClipPlane( GlobalSceneGraph(), plane3_for_points( planepts[0], planepts[1], planepts[2] ) );
246 ClipperChangeNotify();
249 const char* Clip_getShader(){
250 return g_clip_useCaulk ? "textures/common/caulk" : TextureBrowser_GetSelectedShader( GlobalTextureBrowser() );
254 if ( ClipMode() && GlobalClipPoints_valid() ) {
256 AABB bounds( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) );
257 PlanePointsFromClipPoints( planepts, bounds, g_clip_viewtype );
258 Scene_BrushSplitByPlane( GlobalSceneGraph(), planepts[0], planepts[1], planepts[2], Clip_getShader(), ( !g_bSwitch ) ? eFront : eBack );
263 ClipperChangeNotify();
264 if( g_quick_clipper ){
265 g_quick_clipper = false;
272 if ( ClipMode() && GlobalClipPoints_valid() ) {
274 AABB bounds( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) );
275 PlanePointsFromClipPoints( planepts, bounds, g_clip_viewtype );
276 Scene_BrushSplitByPlane( GlobalSceneGraph(), planepts[0], planepts[1], planepts[2], Clip_getShader(), eFrontAndBack );
281 ClipperChangeNotify();
282 if( g_quick_clipper ){
283 g_quick_clipper = false;
290 g_bSwitch = !g_bSwitch;
292 ClipperChangeNotify();
295 void OnClipMode( bool enabled ){
300 if ( !enabled && g_pMovingClip ) {
305 ClipperChangeNotify();
309 return GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eClip;
312 void NewClipPoint( const Vector3& point ){
313 if ( g_Clip1.Set() == false ) {
314 g_Clip1.m_ptClip = point;
317 else if ( g_Clip2.Set() == false ) {
318 g_Clip2.m_ptClip = point;
321 else if ( g_Clip3.Set() == false ) {
322 g_Clip3.m_ptClip = point;
330 g_Clip1.m_ptClip = point;
335 ClipperChangeNotify();
340 struct xywindow_globals_private_t
344 // these are in the View > Show menu with Show coordinates
346 bool show_coordinates;
362 xywindow_globals_private_t() :
366 show_coordinates( false ),
368 show_outline( true ),
371 d_show_work( false ),
373 show_blocks( false ),
375 m_bCamXYUpdate( true ),
376 m_bChaseMouse( true ),
377 m_bSizePaint( true ),
379 g_bCrossHairs( false ){
384 xywindow_globals_t g_xywindow_globals;
385 xywindow_globals_private_t g_xywindow_globals_private;
387 const unsigned int RAD_NONE = 0x00;
388 const unsigned int RAD_SHIFT = 0x01;
389 const unsigned int RAD_ALT = 0x02;
390 const unsigned int RAD_CONTROL = 0x04;
391 const unsigned int RAD_PRESS = 0x08;
392 const unsigned int RAD_LBUTTON = 0x10;
393 const unsigned int RAD_MBUTTON = 0x20;
394 const unsigned int RAD_RBUTTON = 0x40;
396 inline ButtonIdentifier button_for_flags( unsigned int flags ){
397 if ( flags & RAD_LBUTTON ) {
400 if ( flags & RAD_RBUTTON ) {
401 return c_buttonRight;
403 if ( flags & RAD_MBUTTON ) {
404 return c_buttonMiddle;
406 return c_buttonInvalid;
409 inline ModifierFlags modifiers_for_flags( unsigned int flags ){
410 ModifierFlags modifiers = c_modifierNone;
411 if ( flags & RAD_SHIFT ) {
412 modifiers |= c_modifierShift;
414 if ( flags & RAD_CONTROL ) {
415 modifiers |= c_modifierControl;
417 if ( flags & RAD_ALT ) {
418 modifiers |= c_modifierAlt;
423 inline unsigned int buttons_for_button_and_modifiers( ButtonIdentifier button, ModifierFlags flags ){
424 unsigned int buttons = 0;
426 switch ( button.get() )
428 case ButtonEnumeration::INVALID: break;
429 case ButtonEnumeration::LEFT: buttons |= RAD_LBUTTON; break;
430 case ButtonEnumeration::MIDDLE: buttons |= RAD_MBUTTON; break;
431 case ButtonEnumeration::RIGHT: buttons |= RAD_RBUTTON; break;
434 if ( bitfield_enabled( flags, c_modifierControl ) ) {
435 buttons |= RAD_CONTROL;
438 if ( bitfield_enabled( flags, c_modifierShift ) ) {
439 buttons |= RAD_SHIFT;
442 if ( bitfield_enabled( flags, c_modifierAlt ) ) {
449 inline unsigned int buttons_for_event_button( GdkEventButton* event ){
450 unsigned int flags = 0;
452 switch ( event->button )
454 case 1: flags |= RAD_LBUTTON; break;
455 case 2: flags |= RAD_MBUTTON; break;
456 case 3: flags |= RAD_RBUTTON; break;
459 if ( ( event->state & GDK_CONTROL_MASK ) != 0 ) {
460 flags |= RAD_CONTROL;
463 if ( ( event->state & GDK_SHIFT_MASK ) != 0 ) {
467 if ( ( event->state & GDK_MOD1_MASK ) != 0 ) {
474 inline unsigned int buttons_for_state( guint state ){
475 unsigned int flags = 0;
477 if ( ( state & GDK_BUTTON1_MASK ) != 0 ) {
478 flags |= RAD_LBUTTON;
481 if ( ( state & GDK_BUTTON2_MASK ) != 0 ) {
482 flags |= RAD_MBUTTON;
485 if ( ( state & GDK_BUTTON3_MASK ) != 0 ) {
486 flags |= RAD_RBUTTON;
489 if ( ( state & GDK_CONTROL_MASK ) != 0 ) {
490 flags |= RAD_CONTROL;
493 if ( ( state & GDK_SHIFT_MASK ) != 0 ) {
497 if ( ( state & GDK_MOD1_MASK ) != 0 ) {
505 void XYWnd::SetScale( float f ){
509 XYWnd_Update( *this );
512 void XYWnd::ZoomIn(){
513 float max_scale = 64;
514 float scale = Scale() * 5.0f / 4.0f;
515 if ( scale > max_scale ) {
516 if ( Scale() != max_scale ) {
517 SetScale( max_scale );
527 // NOTE: the zoom out factor is 4/5, we could think about customizing it
528 // we don't go below a zoom factor corresponding to 10% of the max world size
529 // (this has to be computed against the window size)
530 void XYWnd::ZoomOut(){
531 float min_scale = MIN( Width(), Height() ) / ( 1.1f * ( g_MaxWorldCoord - g_MinWorldCoord ) );
532 float scale = Scale() * 4.0f / 5.0f;
533 if ( scale < min_scale ) {
534 if ( Scale() != min_scale ) {
535 SetScale( min_scale );
544 void XYWnd::ZoomInWithMouse( int pointx, int pointy ){
545 float old_scale = Scale();
547 if ( g_xywindow_globals.m_bImprovedWheelZoom ) {
548 float scale_diff = 1.0 / old_scale - 1.0 / Scale();
549 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
550 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
551 Vector3 origin = GetOrigin();
552 origin[nDim1] += scale_diff * (pointx - 0.5 * Width());
553 origin[nDim2] -= scale_diff * (pointy - 0.5 * Height());
558 VIEWTYPE GlobalXYWnd_getCurrentViewType(){
559 ASSERT_NOTNULL( g_pParentWnd );
560 ASSERT_NOTNULL( g_pParentWnd->ActiveXY() );
561 return g_pParentWnd->ActiveXY()->GetViewType();
564 // =============================================================================
567 ui::Menu XYWnd::m_mnuDrop(ui::null);
569 // this is disabled, and broken
570 // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=394
574 width = g_pParentWnd->ActiveXY()->Width();
575 height = g_pParentWnd->ActiveXY()->Height();
577 const char* filename;
579 filename = ui::file_dialog( MainFrame_getWindow( ), FALSE, "Save Image", 0, FILTER_BMP );
584 g_pParentWnd->ActiveXY()->MakeCurrent();
585 img = (unsigned char*)malloc( width * height * 3 );
586 glReadPixels( 0,0,width,height,GL_RGB,GL_UNSIGNED_BYTE,img );
589 fp = fopen( filename, "wb" );
592 unsigned long cmap, bfSize;
596 bfSize = 54 + width * height * 3;
598 long byteswritten = 0;
599 long pixoff = 54 + cmap * 4;
601 char m1 = 'B', m2 = 'M';
602 fwrite( &m1, 1, 1, fp ); byteswritten++; // B
603 fwrite( &m2, 1, 1, fp ); byteswritten++; // M
604 fwrite( &bfSize, 4, 1, fp ); byteswritten += 4; // bfSize
605 fwrite( &res, 2, 1, fp ); byteswritten += 2; // bfReserved1
606 fwrite( &res, 2, 1, fp ); byteswritten += 2; // bfReserved2
607 fwrite( &pixoff, 4, 1, fp ); byteswritten += 4; // bfOffBits
609 unsigned long biSize = 40, compress = 0, size = 0;
611 unsigned short planes = 1;
612 fwrite( &biSize, 4, 1, fp ); byteswritten += 4; // biSize
613 fwrite( &width, 4, 1, fp ); byteswritten += 4; // biWidth
614 fwrite( &height, 4, 1, fp ); byteswritten += 4; // biHeight
615 fwrite( &planes, 2, 1, fp ); byteswritten += 2; // biPlanes
616 fwrite( &bits, 2, 1, fp ); byteswritten += 2; // biBitCount
617 fwrite( &compress, 4, 1, fp ); byteswritten += 4; // biCompression
618 fwrite( &size, 4, 1, fp ); byteswritten += 4; // biSizeImage
619 fwrite( &pixels, 4, 1, fp ); byteswritten += 4; // biXPelsPerMeter
620 fwrite( &pixels, 4, 1, fp ); byteswritten += 4; // biYPelsPerMeter
621 fwrite( &cmap, 4, 1, fp ); byteswritten += 4; // biClrUsed
622 fwrite( &cmap, 4, 1, fp ); byteswritten += 4; // biClrImportant
624 unsigned long widthDW = ( ( ( width * 24 ) + 31 ) / 32 * 4 );
625 long row, row_size = width * 3;
626 for ( row = 0; row < height; row++ )
628 unsigned char* buf = img + row * row_size;
632 for ( col = 0; col < row_size; col += 3 )
634 putc( buf[col + 2], fp );
635 putc( buf[col + 1], fp );
636 putc( buf[col], fp );
638 byteswritten += row_size;
641 for ( count = row_size; count < widthDW; count++ )
643 putc( 0, fp ); // dummy
658 Timer g_chasemouse_timer;
660 void XYWnd::ChaseMouse(){
661 float multiplier = g_chasemouse_timer.elapsed_msec() / 10.0f;
662 Scroll( float_to_integer( multiplier * m_chasemouse_delta_x ), float_to_integer( multiplier * -m_chasemouse_delta_y ) );
664 //globalOutputStream() << "chasemouse: multiplier=" << multiplier << " x=" << m_chasemouse_delta_x << " y=" << m_chasemouse_delta_y << '\n';
666 XY_MouseMoved( m_chasemouse_current_x, m_chasemouse_current_y, getButtonState() );
667 g_chasemouse_timer.start();
670 gboolean xywnd_chasemouse( gpointer data ){
671 reinterpret_cast<XYWnd*>( data )->ChaseMouse();
675 inline const int& min_int( const int& left, const int& right ){
676 return std::min( left, right );
679 bool XYWnd::chaseMouseMotion( int pointx, int pointy ){
680 m_chasemouse_delta_x = 0;
681 m_chasemouse_delta_y = 0;
683 if ( g_xywindow_globals_private.m_bChaseMouse && getButtonState() == RAD_LBUTTON ) {
684 const int epsilon = 16;
686 if ( pointx < epsilon ) {
687 m_chasemouse_delta_x = std::max( pointx, 0 ) - epsilon;
689 else if ( ( pointx - m_nWidth ) > -epsilon ) {
690 m_chasemouse_delta_x = min_int( ( pointx - m_nWidth ), 0 ) + epsilon;
693 if ( pointy < epsilon ) {
694 m_chasemouse_delta_y = std::max( pointy, 0 ) - epsilon;
696 else if ( ( pointy - m_nHeight ) > -epsilon ) {
697 m_chasemouse_delta_y = min_int( ( pointy - m_nHeight ), 0 ) + epsilon;
700 if ( m_chasemouse_delta_y != 0 || m_chasemouse_delta_x != 0 ) {
701 //globalOutputStream() << "chasemouse motion: x=" << pointx << " y=" << pointy << "... ";
702 m_chasemouse_current_x = pointx;
703 m_chasemouse_current_y = pointy;
704 if ( m_chasemouse_handler == 0 ) {
705 //globalOutputStream() << "chasemouse timer start... ";
706 g_chasemouse_timer.start();
707 m_chasemouse_handler = g_idle_add( xywnd_chasemouse, this );
713 if ( m_chasemouse_handler != 0 ) {
714 //globalOutputStream() << "chasemouse cancel\n";
715 g_source_remove( m_chasemouse_handler );
716 m_chasemouse_handler = 0;
722 if ( m_chasemouse_handler != 0 ) {
723 //globalOutputStream() << "chasemouse cancel\n";
724 g_source_remove( m_chasemouse_handler );
725 m_chasemouse_handler = 0;
731 // =============================================================================
733 Shader* XYWnd::m_state_selected = 0;
735 void xy_update_xor_rectangle( XYWnd& self, rect_t area ){
736 if ( self.GetWidget().visible() ) {
737 rectangle_t rect = rectangle_from_area( area.min, area.max, self.Width(), self.Height() );
738 // int nDim1 = ( self.GetViewType() == YZ ) ? 1 : 0;
739 // int nDim2 = ( self.GetViewType() == XY ) ? 1 : 2;
740 // rect.x /= self.Scale();
741 // rect.y /= self.Scale();
742 // rect.w /= self.Scale();
743 // rect.h /= self.Scale();
744 // rect.x += self.GetOrigin()[nDim1];
745 // rect.y += self.GetOrigin()[nDim2];
746 self.m_XORRectangle.set( rect );
750 gboolean xywnd_button_press( ui::Widget widget, GdkEventButton* event, XYWnd* xywnd ){
751 if ( event->type == GDK_BUTTON_PRESS ) {
752 if( !xywnd->Active() ){
753 g_pParentWnd->SetActiveXY( xywnd );
756 xywnd->ButtonState_onMouseDown( buttons_for_event_button( event ) );
758 xywnd->onMouseDown( WindowVector( event->x, event->y ), button_for_button( event->button ), modifiers_for_state( event->state ) );
763 gboolean xywnd_button_release( ui::Widget widget, GdkEventButton* event, XYWnd* xywnd ){
764 if ( event->type == GDK_BUTTON_RELEASE ) {
765 xywnd->XY_MouseUp( static_cast<int>( event->x ), static_cast<int>( event->y ), buttons_for_event_button( event ) );
767 xywnd->ButtonState_onMouseUp( buttons_for_event_button( event ) );
772 gboolean xywnd_focus_in( ui::Widget widget, GdkEventFocus* event, XYWnd* xywnd ){
773 if ( event->type == GDK_FOCUS_CHANGE ) {
775 if( !xywnd->Active() ){
776 g_pParentWnd->SetActiveXY( xywnd );
783 void xywnd_motion( gdouble x, gdouble y, guint state, void* data ){
784 if ( reinterpret_cast<XYWnd*>( data )->chaseMouseMotion( static_cast<int>( x ), static_cast<int>( y ) ) ) {
787 reinterpret_cast<XYWnd*>( data )->XY_MouseMoved( static_cast<int>( x ), static_cast<int>( y ), buttons_for_state( state ) );
790 gboolean xywnd_wheel_scroll( ui::Widget widget, GdkEventScroll* event, XYWnd* xywnd ){
791 if( !xywnd->Active() ){
792 g_pParentWnd->SetActiveXY( xywnd );
794 if ( event->direction == GDK_SCROLL_UP ) {
795 xywnd->ZoomInWithMouse( (int)event->x, (int)event->y );
797 else if ( event->direction == GDK_SCROLL_DOWN ) {
803 gboolean xywnd_size_allocate( ui::Widget widget, GtkAllocation* allocation, XYWnd* xywnd ){
804 xywnd->m_nWidth = allocation->width;
805 xywnd->m_nHeight = allocation->height;
806 xywnd->updateProjection();
807 xywnd->m_window_observer->onSizeChanged( xywnd->Width(), xywnd->Height() );
811 gboolean xywnd_expose( ui::Widget widget, GdkEventExpose* event, XYWnd* xywnd ){
812 if ( glwidget_make_current( xywnd->GetWidget() ) != FALSE ) {
813 if ( Map_Valid( g_map ) && ScreenUpdates_Enabled() ) {
814 GlobalOpenGL_debugAssertNoErrors();
816 GlobalOpenGL_debugAssertNoErrors();
818 xywnd->m_XORRectangle.set( rectangle_t() );
820 glwidget_swap_buffers( xywnd->GetWidget() );
826 void XYWnd_CameraMoved( XYWnd& xywnd ){
827 if ( g_xywindow_globals_private.m_bCamXYUpdate ) {
828 //XYWnd_Update( xywnd );
829 xywnd.UpdateCameraIcon();
834 m_gl_widget( glwidget_new( FALSE ) ),
835 m_deferredDraw( WidgetQueueDrawCaller( m_gl_widget ) ),
836 m_deferred_motion( xywnd_motion, this ),
837 m_parent( ui::null ),
838 m_window_observer( NewWindowObserver() ),
839 m_XORRectangle( m_gl_widget ),
840 m_chasemouse_handler( 0 ){
844 m_bNewBrushDrag = false;
845 m_move_started = false;
846 m_zoom_started = false;
857 m_backgroundActivated = false;
864 m_entityCreate = false;
866 m_mnuDrop = ui::Menu(ui::null);
868 GlobalWindowObservers_add( m_window_observer );
869 GlobalWindowObservers_connectWidget( m_gl_widget );
871 m_window_observer->setRectangleDrawCallback( ReferenceCaller<XYWnd, void(rect_t), xy_update_xor_rectangle>( *this ) );
872 m_window_observer->setView( m_view );
874 g_object_ref( m_gl_widget._handle );
876 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 );
877 gtk_widget_set_can_focus( m_gl_widget, true );
879 m_sizeHandler = m_gl_widget.connect( "size_allocate", G_CALLBACK( xywnd_size_allocate ), this );
880 m_exposeHandler = m_gl_widget.on_render( G_CALLBACK( xywnd_expose ), this );
882 m_gl_widget.connect( "button_press_event", G_CALLBACK( xywnd_button_press ), this );
883 m_gl_widget.connect( "button_release_event", G_CALLBACK( xywnd_button_release ), this );
884 m_gl_widget.connect( "focus_in_event", G_CALLBACK( xywnd_focus_in ), this ); //works only in floating views layout
885 m_gl_widget.connect( "motion_notify_event", G_CALLBACK( DeferredMotion::gtk_motion ), &m_deferred_motion );
887 m_gl_widget.connect( "scroll_event", G_CALLBACK( xywnd_wheel_scroll ), this );
889 Map_addValidCallback( g_map, DeferredDrawOnMapValidChangedCaller( m_deferredDraw ) );
894 AddSceneChangeCallback( ReferenceCaller<XYWnd, void(), &XYWnd_Update>( *this ) );
895 AddCameraMovedCallback( ReferenceCaller<XYWnd, void(), &XYWnd_CameraMoved>( *this ) );
897 PressedButtons_connect( g_pressedButtons, m_gl_widget );
899 onMouseDown.connectLast( makeSignalHandler3( MouseDownCaller(), *this ) );
907 m_mnuDrop = ui::Menu(ui::null);
910 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_sizeHandler );
911 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_exposeHandler );
915 m_window_observer->release();
918 void XYWnd::captureStates(){
919 m_state_selected = GlobalShaderCache().capture( "$XY_OVERLAY" );
922 void XYWnd::releaseStates(){
923 GlobalShaderCache().release( "$XY_OVERLAY" );
926 const Vector3& XYWnd::GetOrigin(){
930 void XYWnd::SetOrigin( const Vector3& origin ){
935 void XYWnd::Scroll( int x, int y ){
936 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
937 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
938 m_vOrigin[nDim1] += x / m_fScale;
939 m_vOrigin[nDim2] += y / m_fScale;
944 unsigned int Clipper_buttons(){
948 unsigned int Clipper_quick_buttons(){
949 return RAD_LBUTTON | RAD_CONTROL;
952 void XYWnd::DropClipPoint( int pointx, int pointy ){
955 XY_ToPoint( pointx, pointy, point );
958 Select_GetMid( mid );
959 g_clip_viewtype = static_cast<VIEWTYPE>( GetViewType() );
960 const int nDim = ( g_clip_viewtype == YZ ) ? 0 : ( ( g_clip_viewtype == XZ ) ? 1 : 2 );
961 point[nDim] = mid[nDim];
962 vector3_snap( point, GetSnapGridSize() );
963 NewClipPoint( point );
966 void XYWnd::Clipper_OnLButtonDown( int x, int y ){
967 Vector3 mousePosition;
968 XY_ToPoint( x, y, mousePosition );
969 g_pMovingClip = GlobalClipPoints_Find( mousePosition, (VIEWTYPE)m_viewType, m_fScale );
970 if ( !g_pMovingClip ) {
971 DropClipPoint( x, y );
975 void XYWnd::Clipper_OnLButtonUp( int x, int y ){
976 if ( g_pMovingClip ) {
981 void XYWnd::Clipper_OnMouseMoved( int x, int y ){
982 if ( g_pMovingClip ) {
983 XY_ToPoint( x, y, g_pMovingClip->m_ptClip );
984 XY_SnapToGrid( g_pMovingClip->m_ptClip );
986 ClipperChangeNotify();
990 void XYWnd::Clipper_Crosshair_OnMouseMoved( int x, int y ){
991 Vector3 mousePosition;
992 XY_ToPoint( x, y, mousePosition );
993 if ( ClipMode() && GlobalClipPoints_Find( mousePosition, (VIEWTYPE)m_viewType, m_fScale ) != 0 ) {
995 cursor = gdk_cursor_new( GDK_CROSSHAIR );
996 gdk_window_set_cursor( gtk_widget_get_window(m_gl_widget), cursor );
997 gdk_cursor_unref( cursor );
1001 gdk_window_set_cursor( gtk_widget_get_window(m_gl_widget), 0 );
1005 void XYWnd::SetCustomPivotOrigin( int pointx, int pointy ){
1007 XY_ToPoint( pointx, pointy, point );
1008 VIEWTYPE viewtype = static_cast<VIEWTYPE>( GetViewType() );
1009 const int nDim = ( viewtype == YZ ) ? 0 : ( ( viewtype == XZ ) ? 1 : 2 );
1010 //vector3_snap( point, GetSnapGridSize() );
1011 point[nDim] = 999999;
1013 GlobalSelectionSystem().setCustomPivotOrigin( point );
1014 SceneChangeNotify();
1017 unsigned int MoveCamera_buttons(){
1018 return RAD_CONTROL | ( g_glwindow_globals.m_nMouseType == ETwoButton ? RAD_RBUTTON : RAD_MBUTTON );
1021 void XYWnd_PositionCamera( XYWnd* xywnd, int x, int y, CamWnd& camwnd ){
1022 Vector3 origin( Camera_getOrigin( camwnd ) );
1023 xywnd->XY_ToPoint( x, y, origin );
1024 xywnd->XY_SnapToGrid( origin );
1025 Camera_setOrigin( camwnd, origin );
1028 unsigned int OrientCamera_buttons(){
1029 if ( g_glwindow_globals.m_nMouseType == ETwoButton ) {
1030 return RAD_RBUTTON | RAD_SHIFT | RAD_CONTROL;
1035 void XYWnd_OrientCamera( XYWnd* xywnd, int x, int y, CamWnd& camwnd ){
1036 Vector3 point = g_vector3_identity;
1037 xywnd->XY_ToPoint( x, y, point );
1038 xywnd->XY_SnapToGrid( point );
1039 vector3_subtract( point, Camera_getOrigin( camwnd ) );
1041 int n1 = ( xywnd->GetViewType() == XY ) ? 1 : 2;
1042 int n2 = ( xywnd->GetViewType() == YZ ) ? 1 : 0;
1043 int nAngle = ( xywnd->GetViewType() == XY ) ? CAMERA_YAW : CAMERA_PITCH;
1044 if ( point[n1] || point[n2] ) {
1045 Vector3 angles( Camera_getAngles( camwnd ) );
1046 angles[nAngle] = static_cast<float>( radians_to_degrees( atan2( point[n1], point[n2] ) ) );
1047 Camera_setAngles( camwnd, angles );
1051 unsigned int SetCustomPivotOrigin_buttons(){
1052 return RAD_MBUTTON | RAD_SHIFT;
1060 unsigned int NewBrushDrag_buttons(){
1064 void XYWnd::NewBrushDrag_Begin( int x, int y ){
1066 m_nNewBrushPressx = x;
1067 m_nNewBrushPressy = y;
1069 m_bNewBrushDrag = true;
1070 GlobalUndoSystem().start();
1073 void XYWnd::NewBrushDrag_End( int x, int y ){
1074 if ( m_NewBrushDrag != 0 ) {
1075 GlobalUndoSystem().finish( "brushDragNew" );
1079 void XYWnd::NewBrushDrag( int x, int y ){
1081 XY_ToPoint( m_nNewBrushPressx, m_nNewBrushPressy, mins );
1082 XY_SnapToGrid( mins );
1083 XY_ToPoint( x, y, maxs );
1084 XY_SnapToGrid( maxs );
1086 int nDim = ( m_viewType == XY ) ? 2 : ( m_viewType == YZ ) ? 0 : 1;
1088 mins[nDim] = float_snapped( Select_getWorkZone().d_work_min[nDim], GetSnapGridSize() );
1089 maxs[nDim] = float_snapped( Select_getWorkZone().d_work_max[nDim], GetSnapGridSize() );
1091 if ( maxs[nDim] <= mins[nDim] ) {
1092 maxs[nDim] = mins[nDim] + GetGridSize();
1095 for ( int i = 0 ; i < 3 ; i++ )
1097 if ( mins[i] == maxs[i] ) {
1098 return; // don't create a degenerate brush
1100 if ( mins[i] > maxs[i] ) {
1101 float temp = mins[i];
1107 if ( m_NewBrushDrag == 0 ) {
1108 NodeSmartReference node( GlobalBrushCreator().createBrush() );
1109 Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->insert( node );
1111 scene::Path brushpath( makeReference( GlobalSceneGraph().root() ) );
1112 brushpath.push( makeReference( *Map_GetWorldspawn( g_map ) ) );
1113 brushpath.push( makeReference( node.get() ) );
1114 selectPath( brushpath, true );
1116 m_NewBrushDrag = node.get_pointer();
1120 //Scene_BrushResize_Selected(GlobalSceneGraph(), aabb_for_minmax(mins, maxs), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()));
1121 Scene_BrushResize_Selected( GlobalSceneGraph(), aabb_for_minmax( mins, maxs ),
1122 g_brush_always_caulk ?
1123 "textures/common/caulk" : TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ) );
1126 void entitycreate_activated( ui::Widget item ){
1127 scene::Node* world_node = Map_FindWorldspawn( g_map );
1128 const char* entity_name = gtk_label_get_text( GTK_LABEL( gtk_bin_get_child(GTK_BIN( item )) ) );
1130 if ( !( world_node && string_equal( entity_name, "worldspawn" ) ) ) {
1131 g_pParentWnd->ActiveXY()->OnEntityCreate( entity_name );
1134 GlobalRadiant().m_pfnMessageBox( MainFrame_getWindow(), "There's already a worldspawn in your map!"
1142 void EntityClassMenu_addItem( ui::Menu menu, const char* name ){
1143 auto item = ui::MenuItem( name );
1144 item.connect( "activate", G_CALLBACK( entitycreate_activated ), item );
1146 menu_add_item( menu, item );
1149 class EntityClassMenuInserter : public EntityClassVisitor
1151 typedef std::pair<ui::Menu, CopiedString> MenuPair;
1152 typedef std::vector<MenuPair> MenuStack;
1154 CopiedString m_previous;
1156 EntityClassMenuInserter( ui::Menu menu ){
1157 m_stack.reserve( 2 );
1158 m_stack.push_back( MenuPair( menu, "" ) );
1160 ~EntityClassMenuInserter(){
1161 if ( !string_empty( m_previous.c_str() ) ) {
1162 addItem( m_previous.c_str(), "" );
1165 void visit( EntityClass* e ){
1166 ASSERT_MESSAGE( !string_empty( e->name() ), "entity-class has no name" );
1167 if ( !string_empty( m_previous.c_str() ) ) {
1168 addItem( m_previous.c_str(), e->name() );
1170 m_previous = e->name();
1172 void pushMenu( const CopiedString& name ){
1173 auto item = ui::MenuItem( name.c_str() );
1175 m_stack.back().first.add(item);
1177 auto submenu = ui::Menu(ui::New);
1178 gtk_menu_item_set_submenu( item, submenu );
1180 m_stack.push_back( MenuPair( submenu, name ) );
1185 void addItem( const char* name, const char* next ){
1186 const char* underscore = strchr( name, '_' );
1188 if ( underscore != 0 && underscore != name ) {
1189 bool nextEqual = string_equal_n( name, next, ( underscore + 1 ) - name );
1190 const char* parent = m_stack.back().second.c_str();
1192 if ( !string_empty( parent )
1193 && string_length( parent ) == std::size_t( underscore - name )
1194 && string_equal_n( name, parent, underscore - name ) ) { // this is a child
1196 else if ( nextEqual ) {
1197 if ( m_stack.size() == 2 ) {
1200 pushMenu( CopiedString( StringRange( name, underscore ) ) );
1202 else if ( m_stack.size() == 2 ) {
1206 else if ( m_stack.size() == 2 ) {
1210 EntityClassMenu_addItem( m_stack.back().first, name );
1214 void XYWnd::OnContextMenu(){
1215 if ( g_xywindow_globals.m_bRightClick == false ) {
1219 if ( !m_mnuDrop ) { // first time, load it up
1220 auto menu = m_mnuDrop = ui::Menu(ui::New);
1222 EntityClassMenuInserter inserter( menu );
1223 GlobalEntityClassManager().forEach( inserter );
1226 gtk_menu_popup( m_mnuDrop, 0, 0, 0, 0, 1, GDK_CURRENT_TIME );
1229 FreezePointer g_xywnd_freezePointer;
1231 unsigned int Move_buttons(){
1235 void XYWnd_moveDelta( int x, int y, unsigned int state, void* data ){
1236 reinterpret_cast<XYWnd*>( data )->EntityCreate_MouseMove( x, y );
1237 reinterpret_cast<XYWnd*>( data )->Scroll( -x, y );
1240 gboolean XYWnd_Move_focusOut( ui::Widget widget, GdkEventFocus* event, XYWnd* xywnd ){
1245 void XYWnd::Move_Begin(){
1246 if ( m_move_started ) {
1249 m_move_started = true;
1250 g_xywnd_freezePointer.freeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), m_gl_widget, XYWnd_moveDelta, this );
1251 m_move_focusOut = m_gl_widget.connect( "focus_out_event", G_CALLBACK( XYWnd_Move_focusOut ), this );
1254 void XYWnd::Move_End(){
1255 m_move_started = false;
1256 g_xywnd_freezePointer.unfreeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), false );
1257 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_move_focusOut );
1260 unsigned int Zoom_buttons(){
1261 return RAD_RBUTTON | RAD_ALT;
1266 void XYWnd_zoomDelta( int x, int y, unsigned int state, void* data ){
1269 while ( abs( g_dragZoom ) > 8 )
1271 if ( g_dragZoom > 0 ) {
1272 reinterpret_cast<XYWnd*>( data )->ZoomOut();
1277 reinterpret_cast<XYWnd*>( data )->ZoomIn();
1284 gboolean XYWnd_Zoom_focusOut( ui::Widget widget, GdkEventFocus* event, XYWnd* xywnd ){
1289 void XYWnd::Zoom_Begin(){
1290 if ( m_zoom_started ) {
1293 m_zoom_started = true;
1295 g_xywnd_freezePointer.freeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), m_gl_widget, XYWnd_zoomDelta, this );
1296 m_zoom_focusOut = m_gl_widget.connect( "focus_out_event", G_CALLBACK( XYWnd_Zoom_focusOut ), this );
1299 void XYWnd::Zoom_End(){
1300 m_zoom_started = false;
1301 g_xywnd_freezePointer.unfreeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), false );
1302 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_zoom_focusOut );
1305 // makes sure the selected brush or camera is in view
1306 void XYWnd::PositionView( const Vector3& position ){
1307 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1308 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1310 m_vOrigin[nDim1] = position[nDim1];
1311 m_vOrigin[nDim2] = position[nDim2];
1315 XYWnd_Update( *this );
1318 void XYWnd::SetViewType( VIEWTYPE viewType ){
1319 m_viewType = viewType;
1323 gtk_window_set_title( m_parent, ViewType_getTitle( m_viewType ) );
1328 inline WindowVector WindowVector_forInteger( int x, int y ){
1329 return WindowVector( static_cast<float>( x ), static_cast<float>( y ) );
1332 void XYWnd::mouseDown( const WindowVector& position, ButtonIdentifier button, ModifierFlags modifiers ){
1333 XY_MouseDown( static_cast<int>( position.x() ), static_cast<int>( position.y() ), buttons_for_button_and_modifiers( button, modifiers ) );
1335 void XYWnd::XY_MouseDown( int x, int y, unsigned int buttons ){
1336 if ( buttons == Move_buttons() ) {
1338 EntityCreate_MouseDown( x, y );
1340 else if ( buttons == Zoom_buttons() ) {
1343 else if ( ClipMode() && ( buttons == Clipper_buttons() || buttons == Clipper_quick_buttons() ) ) {
1344 Clipper_OnLButtonDown( x, y );
1346 else if ( !ClipMode() && buttons == Clipper_quick_buttons() ) {
1348 g_quick_clipper = true;
1349 Clipper_OnLButtonDown( x, y );
1351 else if ( buttons == NewBrushDrag_buttons() && GlobalSelectionSystem().countSelected() == 0 ) {
1352 NewBrushDrag_Begin( x, y );
1354 // control mbutton = move camera
1355 else if ( buttons == MoveCamera_buttons() ) {
1356 XYWnd_PositionCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1358 // mbutton = angle camera
1359 else if ( buttons == OrientCamera_buttons() ) {
1360 XYWnd_OrientCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1362 else if ( buttons == SetCustomPivotOrigin_buttons() ) {
1363 SetCustomPivotOrigin( x, y );
1367 m_window_observer->onMouseDown( WindowVector_forInteger( x, y ), button_for_flags( buttons ), modifiers_for_flags( buttons ) );
1371 void XYWnd::XY_MouseUp( int x, int y, unsigned int buttons ){
1372 if ( m_move_started ) {
1374 EntityCreate_MouseUp( x, y );
1376 else if ( m_zoom_started ) {
1379 else if ( ClipMode() && ( buttons == Clipper_buttons() || buttons == Clipper_quick_buttons() ) ) {
1380 Clipper_OnLButtonUp( x, y );
1382 else if ( m_bNewBrushDrag ) {
1383 m_bNewBrushDrag = false;
1384 NewBrushDrag_End( x, y );
1385 if ( m_NewBrushDrag == 0 ) {
1386 //L button w/o created brush = tunnel selection
1387 m_window_observer->onMouseUp( WindowVector_forInteger( x, y ), button_for_flags( buttons ), modifiers_for_flags( buttons ) );
1392 m_window_observer->onMouseUp( WindowVector_forInteger( x, y ), button_for_flags( buttons ), modifiers_for_flags( buttons ) );
1396 void XYWnd::XY_MouseMoved( int x, int y, unsigned int buttons ){
1397 // rbutton = drag xy origin
1398 if ( m_move_started ) {
1401 else if ( m_zoom_started ) {
1404 else if ( ClipMode() && g_pMovingClip != 0 ) {
1405 Clipper_OnMouseMoved( x, y );
1407 // lbutton without selection = drag new brush
1408 else if ( m_bNewBrushDrag ) {
1409 NewBrushDrag( x, y );
1412 // control mbutton = move camera
1413 else if ( getButtonState() == MoveCamera_buttons() ) {
1414 XYWnd_PositionCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1417 // mbutton = angle camera
1418 else if ( getButtonState() == OrientCamera_buttons() ) {
1419 XYWnd_OrientCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1422 else if ( buttons == SetCustomPivotOrigin_buttons() ) {
1423 SetCustomPivotOrigin( x, y );
1428 m_window_observer->onMouseMotion( WindowVector_forInteger( x, y ), modifiers_for_flags( buttons ) );
1430 m_mousePosition[0] = m_mousePosition[1] = m_mousePosition[2] = 0.0;
1431 XY_ToPoint( x, y, m_mousePosition );
1432 XY_SnapToGrid( m_mousePosition );
1434 StringOutputStream status( 64 );
1435 status << "x:: " << FloatFormat( m_mousePosition[0], 6, 1 )
1436 << " y:: " << FloatFormat( m_mousePosition[1], 6, 1 )
1437 << " z:: " << FloatFormat( m_mousePosition[2], 6, 1 );
1438 g_pParentWnd->SetStatusText( g_pParentWnd->m_position_status, status.c_str() );
1440 if ( g_xywindow_globals_private.g_bCrossHairs ) {
1441 XYWnd_Update( *this );
1444 Clipper_Crosshair_OnMouseMoved( x, y );
1448 void XYWnd::EntityCreate_MouseDown( int x, int y ){
1449 m_entityCreate = true;
1450 m_entityCreate_x = x;
1451 m_entityCreate_y = y;
1454 void XYWnd::EntityCreate_MouseMove( int x, int y ){
1455 if ( m_entityCreate && ( m_entityCreate_x != x || m_entityCreate_y != y ) ) {
1456 m_entityCreate = false;
1460 void XYWnd::EntityCreate_MouseUp( int x, int y ){
1461 if ( m_entityCreate ) {
1462 m_entityCreate = false;
1467 inline float screen_normalised( int pos, unsigned int size ){
1468 return ( ( 2.0f * pos ) / size ) - 1.0f;
1471 inline float normalised_to_world( float normalised, float world_origin, float normalised2world_scale ){
1472 return world_origin + normalised * normalised2world_scale;
1476 // TTimo: watch it, this doesn't init one of the 3 coords
1477 void XYWnd::XY_ToPoint( int x, int y, Vector3& point ){
1478 float normalised2world_scale_x = m_nWidth / 2 / m_fScale;
1479 float normalised2world_scale_y = m_nHeight / 2 / m_fScale;
1480 if ( m_viewType == XY ) {
1481 point[0] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[0], normalised2world_scale_x );
1482 point[1] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[1], normalised2world_scale_y );
1484 else if ( m_viewType == YZ ) {
1485 point[1] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[1], normalised2world_scale_x );
1486 point[2] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[2], normalised2world_scale_y );
1490 point[0] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[0], normalised2world_scale_x );
1491 point[2] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[2], normalised2world_scale_y );
1495 void XYWnd::XY_SnapToGrid( Vector3& point ){
1496 if ( m_viewType == XY ) {
1497 point[0] = float_snapped( point[0], GetSnapGridSize() );
1498 point[1] = float_snapped( point[1], GetSnapGridSize() );
1500 else if ( m_viewType == YZ ) {
1501 point[1] = float_snapped( point[1], GetSnapGridSize() );
1502 point[2] = float_snapped( point[2], GetSnapGridSize() );
1506 point[0] = float_snapped( point[0], GetSnapGridSize() );
1507 point[2] = float_snapped( point[2], GetSnapGridSize() );
1511 void XYWnd::XY_LoadBackgroundImage( const char *name ){
1512 const char* relative = path_make_relative( name, GlobalFileSystem().findRoot( name ) );
1513 if ( relative == name ) {
1514 globalOutputStream() << "WARNING: could not extract the relative path, using full path instead\n";
1517 char fileNameWithoutExt[512];
1518 strncpy( fileNameWithoutExt, relative, sizeof( fileNameWithoutExt ) - 1 );
1519 fileNameWithoutExt[512 - 1] = '\0';
1520 fileNameWithoutExt[strlen( fileNameWithoutExt ) - 4] = '\0';
1522 Image *image = QERApp_LoadImage( 0, fileNameWithoutExt );
1524 globalOutputStream() << "Could not load texture " << fileNameWithoutExt << "\n";
1527 g_pParentWnd->ActiveXY()->m_tex = (qtexture_t*)malloc( sizeof( qtexture_t ) );
1528 LoadTextureRGBA( g_pParentWnd->ActiveXY()->XYWnd::m_tex, image->getRGBAPixels(), image->getWidth(), image->getHeight() );
1529 globalOutputStream() << "Loaded background texture " << relative << "\n";
1530 g_pParentWnd->ActiveXY()->m_backgroundActivated = true;
1533 switch ( g_pParentWnd->ActiveXY()->m_viewType )
1550 Select_GetBounds( min, max );
1551 g_pParentWnd->ActiveXY()->m_xmin = min[m_ix];
1552 g_pParentWnd->ActiveXY()->m_ymin = min[m_iy];
1553 g_pParentWnd->ActiveXY()->m_xmax = max[m_ix];
1554 g_pParentWnd->ActiveXY()->m_ymax = max[m_iy];
1557 void XYWnd::XY_DisableBackground( void ){
1558 g_pParentWnd->ActiveXY()->m_backgroundActivated = false;
1559 if ( g_pParentWnd->ActiveXY()->m_tex ) {
1560 free( g_pParentWnd->ActiveXY()->m_tex );
1562 g_pParentWnd->ActiveXY()->m_tex = NULL;
1565 void WXY_BackgroundSelect( void ){
1566 bool brushesSelected = Scene_countSelectedBrushes( GlobalSceneGraph() ) != 0;
1567 if ( !brushesSelected ) {
1568 ui::alert( ui::root, "You have to select some brushes to get the bounding box for.\n",
1569 "No selection", ui::alert_type::OK, ui::alert_icon::Error );
1573 const char *filename = MainFrame_getWindow().file_dialog( TRUE, "Background Image", NULL, NULL );
1574 g_pParentWnd->ActiveXY()->XY_DisableBackground();
1576 g_pParentWnd->ActiveXY()->XY_LoadBackgroundImage( filename );
1581 ============================================================================
1585 ============================================================================
1594 double two_to_the_power( int power ){
1595 return pow( 2.0f, power );
1598 void XYWnd::XY_DrawAxis( void ){
1599 if ( g_xywindow_globals_private.show_axis ) {
1600 const char g_AxisName[3] = { 'X', 'Y', 'Z' };
1601 const int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1602 const int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1603 const int w = ( m_nWidth / 2 / m_fScale );
1604 const int h = ( m_nHeight / 2 / m_fScale );
1606 Vector3 colourX = ( m_viewType == YZ ) ? g_xywindow_globals.AxisColorY : g_xywindow_globals.AxisColorX;
1607 Vector3 colourY = ( m_viewType == XY ) ? g_xywindow_globals.AxisColorY : g_xywindow_globals.AxisColorZ;
1609 float grayX = vector3_dot( colourX, Vector3( 0.2989, 0.5870, 0.1140 ) );
1610 float grayY = vector3_dot( colourY, Vector3( 0.2989, 0.5870, 0.1140 ) );
1611 colourX[0] = colourX[1] = colourX[2] = grayX;
1612 colourY[0] = colourY[1] = colourY[2] = grayY;
1615 // draw two lines with corresponding axis colors to highlight current view
1616 // horizontal line: nDim1 color
1618 glBegin( GL_LINES );
1619 glColor3fv( vector3_to_array( colourX ) );
1620 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1621 glVertex2f( m_vOrigin[nDim1] - w + 65 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1623 glVertex2f( 32 / m_fScale, 0 );
1624 glColor3fv( vector3_to_array( colourY ) );
1625 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1626 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 20 / m_fScale );
1628 glVertex2f( 0, 32 / m_fScale );
1631 // now print axis symbols
1632 glColor3fv( vector3_to_array( colourX ) );
1633 glRasterPos2f( m_vOrigin[nDim1] - w + 55 / m_fScale, m_vOrigin[nDim2] + h - 55 / m_fScale );
1634 GlobalOpenGL().drawChar( g_AxisName[nDim1] );
1635 glRasterPos2f( 28 / m_fScale, -10 / m_fScale );
1636 GlobalOpenGL().drawChar( g_AxisName[nDim1] );
1637 glColor3fv( vector3_to_array( colourY ) );
1638 glRasterPos2f( m_vOrigin[nDim1] - w + 25 / m_fScale, m_vOrigin[nDim2] + h - 30 / m_fScale );
1639 GlobalOpenGL().drawChar( g_AxisName[nDim2] );
1640 glRasterPos2f( -10 / m_fScale, 28 / m_fScale );
1641 GlobalOpenGL().drawChar( g_AxisName[nDim2] );
1645 void XYWnd::RenderActive( void ){
1646 if ( glwidget_make_current( m_gl_widget ) != FALSE ) {
1647 if ( Map_Valid( g_map ) && ScreenUpdates_Enabled() ) {
1648 GlobalOpenGL_debugAssertNoErrors();
1649 glDrawBuffer( GL_FRONT );
1651 if ( g_xywindow_globals_private.show_outline ) {
1652 glMatrixMode( GL_PROJECTION );
1654 glOrtho( 0, m_nWidth, 0, m_nHeight, 0, 1 );
1656 glMatrixMode( GL_MODELVIEW );
1659 if( !Active() ){ //sorta erase
1660 glColor3fv( vector3_to_array( g_xywindow_globals.color_gridmajor ) );
1662 // four view mode doesn't colorize
1663 else if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) {
1664 glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) );
1668 switch ( m_viewType )
1671 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorX ) );
1674 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorY ) );
1677 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorZ ) );
1681 glBegin( GL_LINE_LOOP );
1682 glVertex2f( 0.5, 0.5 );
1683 glVertex2f( m_nWidth - 0.5, 1 );
1684 glVertex2f( m_nWidth - 0.5, m_nHeight - 0.5 );
1685 glVertex2f( 0.5, m_nHeight - 0.5 );
1688 // we do this part (the old way) only if show_axis is disabled
1689 if ( !g_xywindow_globals_private.show_axis ) {
1690 glMatrixMode( GL_PROJECTION );
1692 glOrtho( 0, m_nWidth, 0, m_nHeight, 0, 1 );
1694 glMatrixMode( GL_MODELVIEW );
1698 glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) );
1701 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridtext, 1.0f ) ) );
1704 glDisable( GL_BLEND );
1705 glRasterPos2f( 35, m_nHeight - 20 );
1707 GlobalOpenGL().drawString( ViewType_getTitle( m_viewType ) );
1711 glViewport( 0, 0, m_nWidth, m_nHeight );
1713 glMatrixMode( GL_PROJECTION );
1714 glLoadMatrixf( reinterpret_cast<const float*>( &m_projection ) );
1716 glMatrixMode( GL_MODELVIEW );
1718 glScalef( m_fScale, m_fScale, 1 );
1719 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1720 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1721 glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 );
1723 glDisable( GL_LINE_STIPPLE );
1724 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
1725 glDisableClientState( GL_NORMAL_ARRAY );
1726 glDisableClientState( GL_COLOR_ARRAY );
1727 glDisable( GL_TEXTURE_2D );
1728 glDisable( GL_LIGHTING );
1729 glDisable( GL_COLOR_MATERIAL );
1730 glDisable( GL_DEPTH_TEST );
1731 glDisable( GL_TEXTURE_1D );
1732 glDisable( GL_BLEND );
1734 XYWnd::XY_DrawAxis();
1737 glDrawBuffer( GL_BACK );
1738 GlobalOpenGL_debugAssertNoErrors();
1739 glwidget_make_current( m_gl_widget );
1744 void XYWnd::XY_DrawBackground( void ){
1745 glPushAttrib( GL_ALL_ATTRIB_BITS );
1747 glEnable( GL_TEXTURE_2D );
1748 glEnable( GL_BLEND );
1749 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
1750 glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1751 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
1752 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
1754 glPolygonMode( GL_FRONT, GL_FILL );
1756 glBindTexture( GL_TEXTURE_2D, m_tex->texture_number );
1757 glBegin( GL_QUADS );
1759 glColor4f( 1.0, 1.0, 1.0, m_alpha );
1760 glTexCoord2f( 0.0, 1.0 );
1761 glVertex2f( m_xmin, m_ymin );
1763 glTexCoord2f( 1.0, 1.0 );
1764 glVertex2f( m_xmax, m_ymin );
1766 glTexCoord2f( 1.0, 0.0 );
1767 glVertex2f( m_xmax, m_ymax );
1769 glTexCoord2f( 0.0, 0.0 );
1770 glVertex2f( m_xmin, m_ymax );
1773 glBindTexture( GL_TEXTURE_2D, 0 );
1778 void XYWnd::XY_DrawGrid( void ) {
1779 float x, y, xb, xe, yb, ye;
1782 float step, minor_step, stepx, stepy;
1783 step = minor_step = stepx = stepy = GetGridSize();
1785 int minor_power = Grid_getPower();
1788 while ( ( minor_step * m_fScale ) <= 4.0f ) { // make sure minor grid spacing is at least 4 pixels on the screen
1792 int power = minor_power;
1793 while ( ( power % 3 ) != 0 || ( step * m_fScale ) <= 32.0f ) { // make sure major grid spacing is at least 32 pixels on the screen
1795 step = float(two_to_the_power( power ) );
1797 mask = ( 1 << ( power - minor_power ) ) - 1;
1798 while ( ( stepx * m_fScale ) <= 32.0f ) // text step x must be at least 32
1800 while ( ( stepy * m_fScale ) <= 32.0f ) // text step y must be at least 32
1803 a = ( ( GetSnapGridSize() > 0.0f ) ? 1.0f : 0.3f );
1805 glDisable( GL_TEXTURE_2D );
1806 glDisable( GL_TEXTURE_1D );
1807 glDisable( GL_DEPTH_TEST );
1808 glDisable( GL_BLEND );
1811 w = ( m_nWidth / 2 / m_fScale );
1812 h = ( m_nHeight / 2 / m_fScale );
1814 const int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1815 const int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1817 xb = m_vOrigin[nDim1] - w;
1818 if ( xb < region_mins[nDim1] ) {
1819 xb = region_mins[nDim1];
1821 xb = step * floor( xb / step );
1823 xe = m_vOrigin[nDim1] + w;
1824 if ( xe > region_maxs[nDim1] ) {
1825 xe = region_maxs[nDim1];
1827 xe = step * ceil( xe / step );
1829 yb = m_vOrigin[nDim2] - h;
1830 if ( yb < region_mins[nDim2] ) {
1831 yb = region_mins[nDim2];
1833 yb = step * floor( yb / step );
1835 ye = m_vOrigin[nDim2] + h;
1836 if ( ye > region_maxs[nDim2] ) {
1837 ye = region_maxs[nDim2];
1839 ye = step * ceil( ye / step );
1841 #define COLORS_DIFFER( a,b ) \
1842 ( ( a )[0] != ( b )[0] || \
1843 ( a )[1] != ( b )[1] || \
1844 ( a )[2] != ( b )[2] )
1847 // draw minor blocks
1848 if ( g_xywindow_globals_private.d_showgrid || a < 1.0f ) {
1850 glEnable( GL_BLEND );
1853 if ( COLORS_DIFFER( g_xywindow_globals.color_gridminor, g_xywindow_globals.color_gridback ) ) {
1854 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridminor, a ) ) );
1856 glBegin( GL_LINES );
1858 for ( x = xb ; x < xe ; x += minor_step, ++i ) {
1859 if ( ( i & mask ) != 0 ) {
1860 glVertex2f( x, yb );
1861 glVertex2f( x, ye );
1865 for ( y = yb ; y < ye ; y += minor_step, ++i ) {
1866 if ( ( i & mask ) != 0 ) {
1867 glVertex2f( xb, y );
1868 glVertex2f( xe, y );
1874 // draw major blocks
1875 if ( COLORS_DIFFER( g_xywindow_globals.color_gridmajor, g_xywindow_globals.color_gridminor ) ) {
1876 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridmajor, a ) ) );
1878 glBegin( GL_LINES );
1879 for ( x = xb ; x <= xe ; x += step ) {
1880 glVertex2f( x, yb );
1881 glVertex2f( x, ye );
1883 for ( y = yb ; y <= ye ; y += step ) {
1884 glVertex2f( xb, y );
1885 glVertex2f( xe, y );
1891 glDisable( GL_BLEND );
1895 // draw coordinate text if needed
1896 if ( g_xywindow_globals_private.show_coordinates ) {
1897 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridtext, 1.0f ) ) );
1898 float offx = m_vOrigin[nDim2] + h - ( 4 + GlobalOpenGL().m_font->getPixelAscent() ) / m_fScale;
1899 float offy = m_vOrigin[nDim1] - w + 4 / m_fScale;
1900 for ( x = xb - fmod( xb, stepx ); x <= xe ; x += stepx ) {
1901 glRasterPos2f( x, offx );
1902 sprintf( text, "%g", x );
1903 GlobalOpenGL().drawString( text );
1905 for ( y = yb - fmod( yb, stepy ); y <= ye ; y += stepy ) {
1906 glRasterPos2f( offy, y );
1907 sprintf( text, "%g", y );
1908 GlobalOpenGL().drawString( text );
1912 // we do this part (the old way) only if show_axis is disabled
1913 if ( !g_xywindow_globals_private.show_axis ) {
1915 glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) );
1918 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridtext, 1.0f ) ) );
1921 glRasterPos2f( m_vOrigin[nDim1] - w + 35 / m_fScale, m_vOrigin[nDim2] + h - 20 / m_fScale );
1923 GlobalOpenGL().drawString( ViewType_getTitle( m_viewType ) );
1926 XYWnd::XY_DrawAxis();
1928 // show current work zone?
1929 // the work zone is used to place dropped points and brushes
1930 if ( g_xywindow_globals_private.d_show_work ) {
1931 glColor4f( 1.0f, 0.0f, 0.0f, 1.0f );
1932 glBegin( GL_LINES );
1933 glVertex2f( xb, Select_getWorkZone().d_work_min[nDim2] );
1934 glVertex2f( xe, Select_getWorkZone().d_work_min[nDim2] );
1935 glVertex2f( xb, Select_getWorkZone().d_work_max[nDim2] );
1936 glVertex2f( xe, Select_getWorkZone().d_work_max[nDim2] );
1937 glVertex2f( Select_getWorkZone().d_work_min[nDim1], yb );
1938 glVertex2f( Select_getWorkZone().d_work_min[nDim1], ye );
1939 glVertex2f( Select_getWorkZone().d_work_max[nDim1], yb );
1940 glVertex2f( Select_getWorkZone().d_work_max[nDim1], ye );
1950 void XYWnd::XY_DrawBlockGrid(){
1951 if ( Map_FindWorldspawn( g_map ) == 0 ) {
1954 const char *value = Node_getEntity( *Map_GetWorldspawn( g_map ) )->getKeyValue( "_blocksize" );
1955 if ( strlen( value ) ) {
1956 sscanf( value, "%i", &g_xywindow_globals_private.blockSize );
1959 if ( !g_xywindow_globals_private.blockSize || g_xywindow_globals_private.blockSize > 65536 || g_xywindow_globals_private.blockSize < 1024 ) {
1960 // don't use custom blocksize if it is less than the default, or greater than the maximum world coordinate
1961 g_xywindow_globals_private.blockSize = 1024;
1964 float x, y, xb, xe, yb, ye;
1968 glDisable( GL_TEXTURE_2D );
1969 glDisable( GL_TEXTURE_1D );
1970 glDisable( GL_DEPTH_TEST );
1971 glDisable( GL_BLEND );
1973 w = ( m_nWidth / 2 / m_fScale );
1974 h = ( m_nHeight / 2 / m_fScale );
1976 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1977 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1979 xb = m_vOrigin[nDim1] - w;
1980 if ( xb < region_mins[nDim1] ) {
1981 xb = region_mins[nDim1];
1983 xb = static_cast<float>( g_xywindow_globals_private.blockSize * floor( xb / g_xywindow_globals_private.blockSize ) );
1985 xe = m_vOrigin[nDim1] + w;
1986 if ( xe > region_maxs[nDim1] ) {
1987 xe = region_maxs[nDim1];
1989 xe = static_cast<float>( g_xywindow_globals_private.blockSize * ceil( xe / g_xywindow_globals_private.blockSize ) );
1991 yb = m_vOrigin[nDim2] - h;
1992 if ( yb < region_mins[nDim2] ) {
1993 yb = region_mins[nDim2];
1995 yb = static_cast<float>( g_xywindow_globals_private.blockSize * floor( yb / g_xywindow_globals_private.blockSize ) );
1997 ye = m_vOrigin[nDim2] + h;
1998 if ( ye > region_maxs[nDim2] ) {
1999 ye = region_maxs[nDim2];
2001 ye = static_cast<float>( g_xywindow_globals_private.blockSize * ceil( ye / g_xywindow_globals_private.blockSize ) );
2003 // draw major blocks
2005 glColor3fv( vector3_to_array( g_xywindow_globals.color_gridblock ) );
2008 glBegin( GL_LINES );
2010 for ( x = xb ; x <= xe ; x += g_xywindow_globals_private.blockSize )
2012 glVertex2f( x, yb );
2013 glVertex2f( x, ye );
2016 if ( m_viewType == XY ) {
2017 for ( y = yb ; y <= ye ; y += g_xywindow_globals_private.blockSize )
2019 glVertex2f( xb, y );
2020 glVertex2f( xe, y );
2027 // draw coordinate text if needed
2029 if ( m_viewType == XY && m_fScale > .1 ) {
2030 for ( x = xb ; x < xe ; x += g_xywindow_globals_private.blockSize )
2031 for ( y = yb ; y < ye ; y += g_xywindow_globals_private.blockSize )
2033 glRasterPos2f( x + ( g_xywindow_globals_private.blockSize / 2 ), y + ( g_xywindow_globals_private.blockSize / 2 ) );
2034 sprintf( text, "%i,%i",(int)floor( x / g_xywindow_globals_private.blockSize ), (int)floor( y / g_xywindow_globals_private.blockSize ) );
2035 GlobalOpenGL().drawString( text );
2039 glColor4f( 0, 0, 0, 0 );
2042 void XYWnd::DrawCameraIcon( const Vector3& origin, const Vector3& angles ){
2043 Cam.fov = 48 / m_fScale;
2044 Cam.box = 16 / m_fScale;
2046 if ( m_viewType == XY ) {
2049 Cam.a = degrees_to_radians( angles[CAMERA_YAW] );
2051 else if ( m_viewType == YZ ) {
2054 Cam.a = degrees_to_radians( angles[CAMERA_PITCH] );
2060 Cam.a = degrees_to_radians( angles[CAMERA_PITCH] );
2063 //glColor3f( 0.0, 0.0, 1.0 );
2064 glColor3f( 1.0, 1.0, 1.0 );
2065 glBegin( GL_LINE_STRIP );
2066 glVertex3f( Cam.x - Cam.box,Cam.y,0 );
2067 glVertex3f( Cam.x,Cam.y + ( Cam.box / 2 ),0 );
2068 glVertex3f( Cam.x + Cam.box,Cam.y,0 );
2069 glVertex3f( Cam.x,Cam.y - ( Cam.box / 2 ),0 );
2070 glVertex3f( Cam.x - Cam.box,Cam.y,0 );
2071 glVertex3f( Cam.x + Cam.box,Cam.y,0 );
2074 glBegin( GL_LINE_STRIP );
2075 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 );
2076 glVertex3f( Cam.x, Cam.y, 0 );
2077 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 );
2082 void XYWnd::UpdateCameraIcon( void ){
2083 if ( glwidget_make_current( m_gl_widget ) != FALSE ) {
2084 if ( Map_Valid( g_map ) && ScreenUpdates_Enabled() ) {
2085 GlobalOpenGL_debugAssertNoErrors();
2086 glDrawBuffer( GL_FRONT );
2089 glViewport( 0, 0, m_nWidth, m_nHeight );
2091 glMatrixMode( GL_PROJECTION );
2092 glLoadMatrixf( reinterpret_cast<const float*>( &m_projection ) );
2094 glMatrixMode( GL_MODELVIEW );
2096 glScalef( m_fScale, m_fScale, 1 );
2097 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
2098 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
2099 glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 );
2101 glDisable( GL_LINE_STIPPLE );
2102 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2103 glDisableClientState( GL_NORMAL_ARRAY );
2104 glDisableClientState( GL_COLOR_ARRAY );
2105 glDisable( GL_TEXTURE_2D );
2106 glDisable( GL_LIGHTING );
2107 glDisable( GL_COLOR_MATERIAL );
2108 glDisable( GL_DEPTH_TEST );
2109 glDisable( GL_TEXTURE_1D );
2111 glEnable( GL_BLEND );
2112 glBlendFunc( GL_ONE_MINUS_DST_COLOR, GL_ZERO );
2114 //glColor3f( 0.0, 0.0, 1.0 );
2115 glColor3f( 1.0, 1.0, 1.0 );
2116 glBegin( GL_LINE_STRIP );
2117 glVertex3f( Cam.x - Cam.box,Cam.y,0 );
2118 glVertex3f( Cam.x,Cam.y + ( Cam.box / 2 ),0 );
2119 glVertex3f( Cam.x + Cam.box,Cam.y,0 );
2120 glVertex3f( Cam.x,Cam.y - ( Cam.box / 2 ),0 );
2121 glVertex3f( Cam.x - Cam.box,Cam.y,0 );
2122 glVertex3f( Cam.x + Cam.box,Cam.y,0 );
2125 glBegin( GL_LINE_STRIP );
2126 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 );
2127 glVertex3f( Cam.x, Cam.y, 0 );
2128 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 );
2131 XYWnd::DrawCameraIcon( Camera_getOrigin( *g_pParentWnd->GetCamWnd() ), Camera_getAngles( *g_pParentWnd->GetCamWnd() ) );
2133 glDisable( GL_BLEND );
2136 glDrawBuffer( GL_BACK );
2137 GlobalOpenGL_debugAssertNoErrors();
2138 glwidget_make_current( m_gl_widget );
2144 float Betwixt( float f1, float f2 ){
2146 return f2 + ( ( f1 - f2 ) / 2 );
2149 return f1 + ( ( f2 - f1 ) / 2 );
2154 // can be greatly simplified but per usual i am in a hurry
2155 // which is not an excuse, just a fact
2156 void XYWnd::PaintSizeInfo( int nDim1, int nDim2, Vector3& vMinBounds, Vector3& vMaxBounds ){
2157 if ( vector3_equal( vMinBounds, vMaxBounds ) ) {
2160 const char* g_pDimStrings[] = {"x:", "y:", "z:"};
2161 typedef const char* OrgStrings[2];
2162 const OrgStrings g_pOrgStrings[] = { { "x:", "y:", }, { "x:", "z:", }, { "y:", "z:", } };
2164 Vector3 vSize( vector3_subtracted( vMaxBounds, vMinBounds ) );
2166 glColor3f( g_xywindow_globals.color_selbrushes[0] * .65f,
2167 g_xywindow_globals.color_selbrushes[1] * .65f,
2168 g_xywindow_globals.color_selbrushes[2] * .65f );
2170 StringOutputStream dimensions( 16 );
2172 if ( m_viewType == XY ) {
2173 glBegin( GL_LINES );
2175 glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f );
2176 glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
2178 glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
2179 glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
2181 glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f );
2182 glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
2185 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2], 0.0f );
2186 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f );
2188 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f );
2189 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f );
2191 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2], 0.0f );
2192 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f );
2196 glRasterPos3f( Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), vMinBounds[nDim2] - 20.0f / m_fScale, 0.0f );
2197 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
2198 GlobalOpenGL().drawString( dimensions.c_str() );
2201 glRasterPos3f( vMaxBounds[nDim1] + 16.0f / m_fScale, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ), 0.0f );
2202 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
2203 GlobalOpenGL().drawString( dimensions.c_str() );
2206 glRasterPos3f( vMinBounds[nDim1] + 4, vMaxBounds[nDim2] + 8 / m_fScale, 0.0f );
2207 dimensions << "(" << g_pOrgStrings[0][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[0][1] << vMaxBounds[nDim2] << ")";
2208 GlobalOpenGL().drawString( dimensions.c_str() );
2210 else if ( m_viewType == XZ ) {
2211 glBegin( GL_LINES );
2213 glVertex3f( vMinBounds[nDim1], 0, vMinBounds[nDim2] - 6.0f / m_fScale );
2214 glVertex3f( vMinBounds[nDim1], 0, vMinBounds[nDim2] - 10.0f / m_fScale );
2216 glVertex3f( vMinBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale );
2217 glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale );
2219 glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 6.0f / m_fScale );
2220 glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale );
2223 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, 0,vMinBounds[nDim2] );
2224 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMinBounds[nDim2] );
2226 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMinBounds[nDim2] );
2227 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMaxBounds[nDim2] );
2229 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, 0,vMaxBounds[nDim2] );
2230 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMaxBounds[nDim2] );
2234 glRasterPos3f( Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), 0, vMinBounds[nDim2] - 20.0f / m_fScale );
2235 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
2236 GlobalOpenGL().drawString( dimensions.c_str() );
2239 glRasterPos3f( vMaxBounds[nDim1] + 16.0f / m_fScale, 0, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ) );
2240 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
2241 GlobalOpenGL().drawString( dimensions.c_str() );
2244 glRasterPos3f( vMinBounds[nDim1] + 4, 0, vMaxBounds[nDim2] + 8 / m_fScale );
2245 dimensions << "(" << g_pOrgStrings[1][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[1][1] << vMaxBounds[nDim2] << ")";
2246 GlobalOpenGL().drawString( dimensions.c_str() );
2250 glBegin( GL_LINES );
2252 glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale );
2253 glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2255 glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2256 glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2258 glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale );
2259 glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2262 glVertex3f( 0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2] );
2263 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2] );
2265 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2] );
2266 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2] );
2268 glVertex3f( 0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2] );
2269 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2] );
2273 glRasterPos3f( 0, Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), vMinBounds[nDim2] - 20.0f / m_fScale );
2274 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
2275 GlobalOpenGL().drawString( dimensions.c_str() );
2278 glRasterPos3f( 0, vMaxBounds[nDim1] + 16.0f / m_fScale, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ) );
2279 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
2280 GlobalOpenGL().drawString( dimensions.c_str() );
2283 glRasterPos3f( 0, vMinBounds[nDim1] + 4.0f, vMaxBounds[nDim2] + 8 / m_fScale );
2284 dimensions << "(" << g_pOrgStrings[2][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[2][1] << vMaxBounds[nDim2] << ")";
2285 GlobalOpenGL().drawString( dimensions.c_str() );
2289 class XYRenderer : public Renderer
2297 unsigned int m_highlight;
2301 XYRenderer( RenderStateFlags globalstate, Shader* selected ) :
2302 m_globalstate( globalstate ),
2303 m_state_selected( selected ){
2304 ASSERT_NOTNULL( selected );
2305 m_state_stack.push_back( state_type() );
2308 void SetState( Shader* state, EStyle style ){
2309 ASSERT_NOTNULL( state );
2310 if ( style == eWireframeOnly ) {
2311 m_state_stack.back().m_state = state;
2314 EStyle getStyle() const {
2315 return eWireframeOnly;
2318 m_state_stack.push_back( m_state_stack.back() );
2321 ASSERT_MESSAGE( !m_state_stack.empty(), "popping empty stack" );
2322 m_state_stack.pop_back();
2324 void Highlight( EHighlightMode mode, bool bEnable = true ){
2326 ? m_state_stack.back().m_highlight |= mode
2327 : m_state_stack.back().m_highlight &= ~mode;
2329 void addRenderable( const OpenGLRenderable& renderable, const Matrix4& localToWorld ){
2330 if ( m_state_stack.back().m_highlight & ePrimitive ) {
2331 m_state_selected->addRenderable( renderable, localToWorld );
2335 m_state_stack.back().m_state->addRenderable( renderable, localToWorld );
2339 void render( const Matrix4& modelview, const Matrix4& projection ){
2340 GlobalShaderCache().render( m_globalstate, modelview, projection );
2343 std::vector<state_type> m_state_stack;
2344 RenderStateFlags m_globalstate;
2345 Shader* m_state_selected;
2348 void XYWnd::updateProjection(){
2349 m_projection[0] = 1.0f / static_cast<float>( m_nWidth / 2 );
2350 m_projection[5] = 1.0f / static_cast<float>( m_nHeight / 2 );
2351 m_projection[10] = 1.0f / ( g_MaxWorldCoord * m_fScale );
2353 m_projection[12] = 0.0f;
2354 m_projection[13] = 0.0f;
2355 m_projection[14] = -1.0f;
2367 m_projection[11] = 0.0f;
2369 m_projection[15] = 1.0f;
2371 m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight );
2374 // note: modelview matrix must have a uniform scale, otherwise strange things happen when rendering the rotation manipulator.
2375 void XYWnd::updateModelview(){
2376 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
2377 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
2380 m_modelview[12] = -m_vOrigin[nDim1] * m_fScale;
2381 m_modelview[13] = -m_vOrigin[nDim2] * m_fScale;
2382 m_modelview[14] = g_MaxWorldCoord * m_fScale;
2385 switch ( m_viewType )
2388 m_modelview[0] = m_fScale;
2393 m_modelview[5] = m_fScale;
2398 m_modelview[10] = -m_fScale;
2401 m_modelview[0] = m_fScale;
2407 m_modelview[6] = m_fScale;
2410 m_modelview[9] = m_fScale;
2411 m_modelview[10] = 0;
2416 m_modelview[2] = -m_fScale;
2418 m_modelview[4] = m_fScale;
2423 m_modelview[9] = m_fScale;
2424 m_modelview[10] = 0;
2428 m_modelview[3] = m_modelview[7] = m_modelview[11] = 0;
2429 m_modelview[15] = 1;
2431 m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight );
2440 //#define DBG_SCENEDUMP
2442 void XYWnd::XY_Draw(){
2446 glViewport( 0, 0, m_nWidth, m_nHeight );
2447 glClearColor( g_xywindow_globals.color_gridback[0],
2448 g_xywindow_globals.color_gridback[1],
2449 g_xywindow_globals.color_gridback[2],0 );
2451 glClear( GL_COLOR_BUFFER_BIT );
2457 glMatrixMode( GL_PROJECTION );
2458 glLoadMatrixf( reinterpret_cast<const float*>( &m_projection ) );
2460 glMatrixMode( GL_MODELVIEW );
2462 glScalef( m_fScale, m_fScale, 1 );
2463 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
2464 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
2465 glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 );
2467 glDisable( GL_LINE_STIPPLE );
2469 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2470 glDisableClientState( GL_NORMAL_ARRAY );
2471 glDisableClientState( GL_COLOR_ARRAY );
2472 glDisable( GL_TEXTURE_2D );
2473 glDisable( GL_LIGHTING );
2474 glDisable( GL_COLOR_MATERIAL );
2475 glDisable( GL_DEPTH_TEST );
2477 if ( m_backgroundActivated ) {
2478 XY_DrawBackground();
2482 if ( g_xywindow_globals_private.show_blocks ) {
2486 glLoadMatrixf( reinterpret_cast<const float*>( &m_modelview ) );
2488 unsigned int globalstate = RENDER_COLOURARRAY | RENDER_COLOURWRITE | RENDER_POLYGONSMOOTH | RENDER_LINESMOOTH;
2489 if ( !g_xywindow_globals.m_bNoStipple ) {
2490 globalstate |= RENDER_LINESTIPPLE;
2494 XYRenderer renderer( globalstate, m_state_selected );
2496 Scene_Render( renderer, m_view );
2498 GlobalOpenGL_debugAssertNoErrors();
2499 renderer.render( m_modelview, m_projection );
2500 GlobalOpenGL_debugAssertNoErrors();
2503 glDepthMask( GL_FALSE );
2505 GlobalOpenGL_debugAssertNoErrors();
2507 glLoadMatrixf( reinterpret_cast<const float*>( &m_modelview ) );
2509 GlobalOpenGL_debugAssertNoErrors();
2510 glDisable( GL_LINE_STIPPLE );
2511 GlobalOpenGL_debugAssertNoErrors();
2513 GlobalOpenGL_debugAssertNoErrors();
2514 if ( GlobalOpenGL().GL_1_3() ) {
2515 glActiveTexture( GL_TEXTURE0 );
2516 glClientActiveTexture( GL_TEXTURE0 );
2518 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2519 GlobalOpenGL_debugAssertNoErrors();
2520 glDisableClientState( GL_NORMAL_ARRAY );
2521 GlobalOpenGL_debugAssertNoErrors();
2522 glDisableClientState( GL_COLOR_ARRAY );
2523 GlobalOpenGL_debugAssertNoErrors();
2524 glDisable( GL_TEXTURE_2D );
2525 GlobalOpenGL_debugAssertNoErrors();
2526 glDisable( GL_LIGHTING );
2527 GlobalOpenGL_debugAssertNoErrors();
2528 glDisable( GL_COLOR_MATERIAL );
2529 GlobalOpenGL_debugAssertNoErrors();
2531 GlobalOpenGL_debugAssertNoErrors();
2535 if ( g_xywindow_globals_private.m_bSizePaint && GlobalSelectionSystem().countSelected() != 0 ) {
2537 Select_GetBounds( min, max );
2538 PaintSizeInfo( nDim1, nDim2, min, max );
2541 if ( g_xywindow_globals_private.g_bCrossHairs ) {
2542 glColor4f( 0.2f, 0.9f, 0.2f, 0.8f );
2543 glBegin( GL_LINES );
2544 if ( m_viewType == XY ) {
2545 glVertex2f( 2.0f * g_MinWorldCoord, m_mousePosition[1] );
2546 glVertex2f( 2.0f * g_MaxWorldCoord, m_mousePosition[1] );
2547 glVertex2f( m_mousePosition[0], 2.0f * g_MinWorldCoord );
2548 glVertex2f( m_mousePosition[0], 2.0f * g_MaxWorldCoord );
2550 else if ( m_viewType == YZ ) {
2551 glVertex3f( m_mousePosition[0], 2.0f * g_MinWorldCoord, m_mousePosition[2] );
2552 glVertex3f( m_mousePosition[0], 2.0f * g_MaxWorldCoord, m_mousePosition[2] );
2553 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MinWorldCoord );
2554 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MaxWorldCoord );
2558 glVertex3f( 2.0f * g_MinWorldCoord, m_mousePosition[1], m_mousePosition[2] );
2559 glVertex3f( 2.0f * g_MaxWorldCoord, m_mousePosition[1], m_mousePosition[2] );
2560 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MinWorldCoord );
2561 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MaxWorldCoord );
2567 GlobalClipPoints_Draw( m_fScale );
2570 GlobalOpenGL_debugAssertNoErrors();
2574 glScalef( m_fScale, m_fScale, 1 );
2575 glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 );
2577 glEnable( GL_BLEND );
2578 glBlendFunc( GL_ONE_MINUS_DST_COLOR, GL_ZERO );
2579 DrawCameraIcon( Camera_getOrigin( *g_pParentWnd->GetCamWnd() ), Camera_getAngles( *g_pParentWnd->GetCamWnd() ) );
2580 glDisable( GL_BLEND );
2582 Feedback_draw2D( m_viewType );
2584 if ( g_xywindow_globals_private.show_outline ) {
2586 glMatrixMode( GL_PROJECTION );
2588 glOrtho( 0, m_nWidth, 0, m_nHeight, 0, 1 );
2590 glMatrixMode( GL_MODELVIEW );
2593 // four view mode doesn't colorize
2594 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) {
2595 glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) );
2599 switch ( m_viewType )
2602 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorX ) );
2605 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorY ) );
2608 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorZ ) );
2612 glBegin( GL_LINE_LOOP );
2613 glVertex2f( 0.5, 0.5 );
2614 glVertex2f( m_nWidth - 0.5, 1 );
2615 glVertex2f( m_nWidth - 0.5, m_nHeight - 0.5 );
2616 glVertex2f( 0.5, m_nHeight - 0.5 );
2621 GlobalOpenGL_debugAssertNoErrors();
2626 void XYWnd_MouseToPoint( XYWnd* xywnd, int x, int y, Vector3& point ){
2627 xywnd->XY_ToPoint( x, y, point );
2628 xywnd->XY_SnapToGrid( point );
2630 int nDim = ( xywnd->GetViewType() == XY ) ? 2 : ( xywnd->GetViewType() == YZ ) ? 0 : 1;
2631 float fWorkMid = float_mid( Select_getWorkZone().d_work_min[nDim], Select_getWorkZone().d_work_max[nDim] );
2632 point[nDim] = float_snapped( fWorkMid, GetGridSize() );
2635 void XYWnd::OnEntityCreate( const char* item ){
2636 StringOutputStream command;
2637 command << "entityCreate -class " << item;
2638 UndoableCommand undo( command.c_str() );
2640 XYWnd_MouseToPoint( this, m_entityCreate_x, m_entityCreate_y, point );
2641 Entity_createFromSelection( item, point );
2646 void GetFocusPosition( Vector3& position ){
2647 if ( GlobalSelectionSystem().countSelected() != 0 ) {
2648 Select_GetMid( position );
2652 position = Camera_getOrigin( *g_pParentWnd->GetCamWnd() );
2656 void XYWnd_Focus( XYWnd* xywnd ){
2658 GetFocusPosition( position );
2659 xywnd->PositionView( position );
2662 void XY_Split_Focus(){
2664 GetFocusPosition( position );
2665 if ( g_pParentWnd->GetXYWnd() ) {
2666 g_pParentWnd->GetXYWnd()->PositionView( position );
2668 if ( g_pParentWnd->GetXZWnd() ) {
2669 g_pParentWnd->GetXZWnd()->PositionView( position );
2671 if ( g_pParentWnd->GetYZWnd() ) {
2672 g_pParentWnd->GetYZWnd()->PositionView( position );
2677 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) {
2678 // cannot do this in a split window
2679 // do something else that the user may want here
2684 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2685 XYWnd_Focus( xywnd );
2688 void XY_TopFrontSide( VIEWTYPE viewtype ){
2689 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) {
2690 // cannot do this in a split window
2691 // do something else that the user may want here
2695 XYWnd* xywnd = g_pParentWnd->CurrentStyle() == MainFrame::eFloating ? g_pParentWnd->ActiveXY() : g_pParentWnd->GetXYWnd();
2696 xywnd->SetViewType( viewtype );
2697 XYWnd_Focus( xywnd );
2701 XY_TopFrontSide( XY );
2705 XY_TopFrontSide( XZ );
2709 XY_TopFrontSide( YZ );
2712 void XY_NextView( XYWnd* xywnd ){
2713 if ( xywnd->GetViewType() == XY ) {
2714 xywnd->SetViewType( XZ );
2716 else if ( xywnd->GetViewType() == XZ ) {
2717 xywnd->SetViewType( YZ );
2720 xywnd->SetViewType( XY );
2722 XYWnd_Focus( xywnd );
2726 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) {
2727 // cannot do this in a split window
2728 // do something else that the user may want here
2732 XYWnd* xywnd = g_pParentWnd->CurrentStyle() == MainFrame::eFloating ? g_pParentWnd->ActiveXY() : g_pParentWnd->GetXYWnd();
2733 XY_NextView( xywnd );
2737 if ( g_pParentWnd->GetXYWnd() ) {
2738 g_pParentWnd->GetXYWnd()->SetScale( 1 );
2740 if ( g_pParentWnd->GetXZWnd() ) {
2741 g_pParentWnd->GetXZWnd()->SetScale( 1 );
2743 if ( g_pParentWnd->GetYZWnd() ) {
2744 g_pParentWnd->GetYZWnd()->SetScale( 1 );
2749 g_pParentWnd->ActiveXY()->ZoomIn();
2752 // NOTE: the zoom out factor is 4/5, we could think about customizing it
2753 // we don't go below a zoom factor corresponding to 10% of the max world size
2754 // (this has to be computed against the window size)
2756 g_pParentWnd->ActiveXY()->ZoomOut();
2761 void ToggleShowCrosshair(){
2762 g_xywindow_globals_private.g_bCrossHairs ^= 1;
2763 XY_UpdateAllWindows();
2766 void ToggleShowSizeInfo(){
2767 g_xywindow_globals_private.m_bSizePaint = !g_xywindow_globals_private.m_bSizePaint;
2768 XY_UpdateAllWindows();
2771 void ToggleShowGrid(){
2772 g_xywindow_globals_private.d_showgrid = !g_xywindow_globals_private.d_showgrid;
2773 XY_UpdateAllWindows();
2776 ToggleShown g_xy_top_shown( true );
2778 void XY_Top_Shown_Construct( ui::Window parent ){
2779 g_xy_top_shown.connect( parent );
2782 ToggleShown g_yz_side_shown( false );
2784 void YZ_Side_Shown_Construct( ui::Window parent ){
2785 g_yz_side_shown.connect( parent );
2788 ToggleShown g_xz_front_shown( false );
2790 void XZ_Front_Shown_Construct( ui::Window parent ){
2791 g_xz_front_shown.connect( parent );
2795 class EntityClassMenu : public ModuleObserver
2797 std::size_t m_unrealised;
2799 EntityClassMenu() : m_unrealised( 1 ){
2802 if ( --m_unrealised == 0 ) {
2806 if ( ++m_unrealised == 1 ) {
2807 if ( XYWnd::m_mnuDrop ) {
2808 XYWnd::m_mnuDrop.destroy();
2809 XYWnd::m_mnuDrop = ui::Menu(ui::null);
2815 EntityClassMenu g_EntityClassMenu;
2820 void ShowNamesToggle(){
2821 GlobalEntityCreator().setShowNames( !GlobalEntityCreator().getShowNames() );
2822 XY_UpdateAllWindows();
2825 typedef FreeCaller<void(), ShowNamesToggle> ShowNamesToggleCaller;
2827 void ShowNamesExport( const Callback<void(bool)> & importer ){
2828 importer( GlobalEntityCreator().getShowNames() );
2831 typedef FreeCaller<void(const Callback<void(bool)> &), ShowNamesExport> ShowNamesExportCaller;
2834 void ShowAnglesToggle(){
2835 GlobalEntityCreator().setShowAngles( !GlobalEntityCreator().getShowAngles() );
2836 XY_UpdateAllWindows();
2839 typedef FreeCaller<void(), ShowAnglesToggle> ShowAnglesToggleCaller;
2841 void ShowAnglesExport( const Callback<void(bool)> & importer ){
2842 importer( GlobalEntityCreator().getShowAngles() );
2844 typedef FreeCaller<void(const Callback<void(bool)> &), ShowAnglesExport> ShowAnglesExportCaller;
2847 void ShowBlocksToggle(){
2848 g_xywindow_globals_private.show_blocks ^= 1;
2849 XY_UpdateAllWindows();
2852 typedef FreeCaller<void(), ShowBlocksToggle> ShowBlocksToggleCaller;
2854 void ShowBlocksExport( const Callback<void(bool)> & importer ){
2855 importer( g_xywindow_globals_private.show_blocks );
2858 typedef FreeCaller<void(const Callback<void(bool)> &), ShowBlocksExport> ShowBlocksExportCaller;
2861 void ShowCoordinatesToggle(){
2862 g_xywindow_globals_private.show_coordinates ^= 1;
2863 XY_UpdateAllWindows();
2866 typedef FreeCaller<void(), ShowCoordinatesToggle> ShowCoordinatesToggleCaller;
2868 void ShowCoordinatesExport( const Callback<void(bool)> & importer ){
2869 importer( g_xywindow_globals_private.show_coordinates );
2872 typedef FreeCaller<void(const Callback<void(bool)> &), ShowCoordinatesExport> ShowCoordinatesExportCaller;
2875 void ShowOutlineToggle(){
2876 g_xywindow_globals_private.show_outline ^= 1;
2877 XY_UpdateAllWindows();
2880 typedef FreeCaller<void(), ShowOutlineToggle> ShowOutlineToggleCaller;
2882 void ShowOutlineExport( const Callback<void(bool)> & importer ){
2883 importer( g_xywindow_globals_private.show_outline );
2886 typedef FreeCaller<void(const Callback<void(bool)> &), ShowOutlineExport> ShowOutlineExportCaller;
2889 void ShowAxesToggle(){
2890 g_xywindow_globals_private.show_axis ^= 1;
2891 XY_UpdateAllWindows();
2893 typedef FreeCaller<void(), ShowAxesToggle> ShowAxesToggleCaller;
2895 void ShowAxesExport( const Callback<void(bool)> & importer ){
2896 importer( g_xywindow_globals_private.show_axis );
2899 typedef FreeCaller<void(const Callback<void(bool)> &), ShowAxesExport> ShowAxesExportCaller;
2902 void ShowWorkzoneToggle(){
2903 g_xywindow_globals_private.d_show_work ^= 1;
2904 XY_UpdateAllWindows();
2906 typedef FreeCaller<void(), ShowWorkzoneToggle> ShowWorkzoneToggleCaller;
2908 void ShowWorkzoneExport( const Callback<void(bool)> & importer ){
2909 importer( g_xywindow_globals_private.d_show_work );
2912 typedef FreeCaller<void(const Callback<void(bool)> &), ShowWorkzoneExport> ShowWorkzoneExportCaller;
2915 BoolExportCaller g_texdef_movelock_caller( g_brush_texturelock_enabled );
2916 ToggleItem g_texdef_movelock_item( g_texdef_movelock_caller );
2918 void Texdef_ToggleMoveLock(){
2919 g_brush_texturelock_enabled = !g_brush_texturelock_enabled;
2920 g_texdef_movelock_item.update();
2925 void ShowSizeToggle(){
2926 g_xywindow_globals_private.m_bSizePaint = !g_xywindow_globals_private.m_bSizePaint;
2927 XY_UpdateAllWindows();
2929 typedef FreeCaller<void(), ShowSizeToggle> ShowSizeToggleCaller;
2930 void ShowSizeExport( const Callback<void(bool)> & importer ){
2931 importer( g_xywindow_globals_private.m_bSizePaint );
2933 typedef FreeCaller<void(const Callback<void(bool)> &), ShowSizeExport> ShowSizeExportCaller;
2936 void ShowCrosshairToggle(){
2937 g_xywindow_globals_private.g_bCrossHairs ^= 1;
2938 XY_UpdateAllWindows();
2940 typedef FreeCaller<void(), ShowCrosshairToggle> ShowCrosshairToggleCaller;
2941 void ShowCrosshairExport( const Callback<void(bool)> & importer ){
2942 importer( g_xywindow_globals_private.g_bCrossHairs );
2944 typedef FreeCaller<void(const Callback<void(bool)> &), ShowCrosshairExport> ShowCrosshairExportCaller;
2947 void ShowGridToggle(){
2948 g_xywindow_globals_private.d_showgrid = !g_xywindow_globals_private.d_showgrid;
2949 XY_UpdateAllWindows();
2951 typedef FreeCaller<void(), ShowGridToggle> ShowGridToggleCaller;
2952 void ShowGridTExport( const Callback<void(bool)> & importer ){
2953 importer( g_xywindow_globals_private.d_showgrid );
2955 typedef FreeCaller<void(const Callback<void(bool)> &), ShowSizeExport> ShowGridExportCaller;
2958 ShowNamesExportCaller g_show_names_caller;
2959 Callback<void(const Callback<void(bool)> &)> g_show_names_callback( g_show_names_caller );
2960 ToggleItem g_show_names( g_show_names_callback );
2962 ShowAnglesExportCaller g_show_angles_caller;
2963 Callback<void(const Callback<void(bool)> &)> g_show_angles_callback( g_show_angles_caller );
2964 ToggleItem g_show_angles( g_show_angles_callback );
2966 ShowBlocksExportCaller g_show_blocks_caller;
2967 Callback<void(const Callback<void(bool)> &)> g_show_blocks_callback( g_show_blocks_caller );
2968 ToggleItem g_show_blocks( g_show_blocks_callback );
2970 ShowCoordinatesExportCaller g_show_coordinates_caller;
2971 Callback<void(const Callback<void(bool)> &)> g_show_coordinates_callback( g_show_coordinates_caller );
2972 ToggleItem g_show_coordinates( g_show_coordinates_callback );
2974 ShowOutlineExportCaller g_show_outline_caller;
2975 Callback<void(const Callback<void(bool)> &)> g_show_outline_callback( g_show_outline_caller );
2976 ToggleItem g_show_outline( g_show_outline_callback );
2978 ShowAxesExportCaller g_show_axes_caller;
2979 Callback<void(const Callback<void(bool)> &)> g_show_axes_callback( g_show_axes_caller );
2980 ToggleItem g_show_axes( g_show_axes_callback );
2982 ShowWorkzoneExportCaller g_show_workzone_caller;
2983 Callback<void(const Callback<void(bool)> &)> g_show_workzone_callback( g_show_workzone_caller );
2984 ToggleItem g_show_workzone( g_show_workzone_callback );
2986 ShowSizeExportCaller g_show_size_caller;
2987 Callback<void(const Callback<void(bool)> &)> g_show_size_callback( g_show_size_caller );
2988 ToggleItem g_show_size( g_show_size_callback );
2990 ShowCrosshairExportCaller g_show_crosshair_caller;
2991 Callback<void(const Callback<void(bool)> &)> g_show_crosshair_callback( g_show_crosshair_caller );
2992 ToggleItem g_show_crosshair( g_show_crosshair_callback );
2994 ShowGridExportCaller g_show_grid_caller;
2995 Callback<void(const Callback<void(bool)> &)> g_show_grid_callback( g_show_grid_caller );
2996 ToggleItem g_show_grid( g_show_grid_callback );
2999 void XYShow_registerCommands(){
3000 GlobalToggles_insert( "ToggleSizePaint", ShowSizeToggleCaller(), ToggleItem::AddCallbackCaller( g_show_size ), Accelerator( 'J' ) );
3001 GlobalToggles_insert( "ToggleCrosshairs", ShowCrosshairToggleCaller(), ToggleItem::AddCallbackCaller( g_show_crosshair ), Accelerator( 'X', (GdkModifierType)GDK_SHIFT_MASK ) );
3002 GlobalToggles_insert( "ToggleGrid", ShowGridToggleCaller(), ToggleItem::AddCallbackCaller( g_show_grid ), Accelerator( '0' ) );
3004 GlobalToggles_insert( "ShowAngles", ShowAnglesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_angles ) );
3005 GlobalToggles_insert( "ShowNames", ShowNamesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_names ) );
3006 GlobalToggles_insert( "ShowBlocks", ShowBlocksToggleCaller(), ToggleItem::AddCallbackCaller( g_show_blocks ) );
3007 GlobalToggles_insert( "ShowCoordinates", ShowCoordinatesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_coordinates ) );
3008 GlobalToggles_insert( "ShowWindowOutline", ShowOutlineToggleCaller(), ToggleItem::AddCallbackCaller( g_show_outline ) );
3009 GlobalToggles_insert( "ShowAxes", ShowAxesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_axes ) );
3010 GlobalToggles_insert( "ShowWorkzone", ShowWorkzoneToggleCaller(), ToggleItem::AddCallbackCaller( g_show_workzone ) );
3013 void XYWnd_registerShortcuts(){
3014 command_connect_accelerator( "ToggleCrosshairs" );
3015 command_connect_accelerator( "ToggleSizePaint" );
3020 void Orthographic_constructPreferences( PreferencesPage& page ){
3021 page.appendCheckBox( "", "Solid selection boxes ( no stipple )", g_xywindow_globals.m_bNoStipple );
3022 //page.appendCheckBox( "", "Display size info", g_xywindow_globals_private.m_bSizePaint );
3023 page.appendCheckBox( "", "Chase mouse during drags", g_xywindow_globals_private.m_bChaseMouse );
3024 page.appendCheckBox( "", "Update views on camera move", g_xywindow_globals_private.m_bCamXYUpdate );
3026 void Orthographic_constructPage( PreferenceGroup& group ){
3027 PreferencesPage page( group.createPage( "Orthographic", "Orthographic View Preferences" ) );
3028 Orthographic_constructPreferences( page );
3030 void Orthographic_registerPreferencesPage(){
3031 PreferencesDialog_addSettingsPage( makeCallbackF(Orthographic_constructPage) );
3034 void Clipper_constructPreferences( PreferencesPage& page ){
3035 page.appendCheckBox( "", "Clipper tool uses caulk", g_clip_useCaulk );
3037 void Clipper_constructPage( PreferenceGroup& group ){
3038 PreferencesPage page( group.createPage( "Clipper", "Clipper Tool Settings" ) );
3039 Clipper_constructPreferences( page );
3041 void Clipper_registerPreferencesPage(){
3042 PreferencesDialog_addSettingsPage( makeCallbackF(Clipper_constructPage) );
3046 #include "preferencesystem.h"
3047 #include "stringio.h"
3050 struct ToggleShown_Bool {
3051 static void Export(const ToggleShown &self, const Callback<void(bool)> &returnz) {
3052 returnz(self.active());
3055 static void Import(ToggleShown &self, bool value) {
3061 void XYWindow_Construct(){
3062 // GlobalCommands_insert( "ToggleCrosshairs", makeCallbackF(ToggleShowCrosshair), Accelerator( 'X', (GdkModifierType)GDK_SHIFT_MASK ) );
3063 // GlobalCommands_insert( "ToggleSizePaint", makeCallbackF(ToggleShowSizeInfo), Accelerator( 'J' ) );
3064 // GlobalCommands_insert( "ToggleGrid", makeCallbackF(ToggleShowGrid), Accelerator( '0' ) );
3066 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 ) ) );
3067 GlobalToggles_insert( "ToggleSideView", ToggleShown::ToggleCaller( g_yz_side_shown ), ToggleItem::AddCallbackCaller( g_yz_side_shown.m_item ) );
3068 GlobalToggles_insert( "ToggleFrontView", ToggleShown::ToggleCaller( g_xz_front_shown ), ToggleItem::AddCallbackCaller( g_xz_front_shown.m_item ) );
3069 GlobalCommands_insert( "NextView", makeCallbackF(XY_Next), Accelerator( GDK_KEY_Tab, (GdkModifierType)GDK_CONTROL_MASK ) ); // fixme: doesn't show its shortcut
3070 GlobalCommands_insert( "ZoomIn", makeCallbackF(XY_ZoomIn), Accelerator( GDK_KEY_Delete ) );
3071 GlobalCommands_insert( "ZoomOut", makeCallbackF(XY_ZoomOut), Accelerator( GDK_KEY_Insert ) );
3072 GlobalCommands_insert( "ViewTop", makeCallbackF(XY_Top), Accelerator( GDK_KEY_KP_Home ) );
3073 GlobalCommands_insert( "ViewSide", makeCallbackF(XY_Side), Accelerator( GDK_KEY_KP_Page_Down ) );
3074 GlobalCommands_insert( "ViewFront", makeCallbackF(XY_Front), Accelerator( GDK_KEY_KP_End ) );
3075 GlobalCommands_insert( "Zoom100", makeCallbackF(XY_Zoom100) );
3076 GlobalCommands_insert( "CenterXYView", makeCallbackF(XY_Focus), Accelerator( GDK_KEY_Tab, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
3078 GlobalPreferenceSystem().registerPreference( "ClipCaulk", make_property_string( g_clip_useCaulk ) );
3080 GlobalPreferenceSystem().registerPreference( "NewRightClick", make_property_string( g_xywindow_globals.m_bRightClick ) );
3081 GlobalPreferenceSystem().registerPreference( "ImprovedWheelZoom", make_property_string( g_xywindow_globals.m_bImprovedWheelZoom ) );
3082 GlobalPreferenceSystem().registerPreference( "ChaseMouse", make_property_string( g_xywindow_globals_private.m_bChaseMouse ) );
3083 GlobalPreferenceSystem().registerPreference( "SizePainting", make_property_string( g_xywindow_globals_private.m_bSizePaint ) );
3084 GlobalPreferenceSystem().registerPreference( "ShowCrosshair", make_property_string( g_xywindow_globals_private.g_bCrossHairs ) );
3085 GlobalPreferenceSystem().registerPreference( "NoStipple", make_property_string( g_xywindow_globals.m_bNoStipple ) );
3086 GlobalPreferenceSystem().registerPreference( "SI_ShowCoords", make_property_string( g_xywindow_globals_private.show_coordinates ) );
3087 GlobalPreferenceSystem().registerPreference( "SI_ShowOutlines", make_property_string( g_xywindow_globals_private.show_outline ) );
3088 GlobalPreferenceSystem().registerPreference( "SI_ShowAxis", make_property_string( g_xywindow_globals_private.show_axis ) );
3089 GlobalPreferenceSystem().registerPreference( "CamXYUpdate", make_property_string( g_xywindow_globals_private.m_bCamXYUpdate ) );
3090 GlobalPreferenceSystem().registerPreference( "ShowWorkzone", make_property_string( g_xywindow_globals_private.d_show_work ) );
3092 GlobalPreferenceSystem().registerPreference( "SI_AxisColors0", make_property_string( g_xywindow_globals.AxisColorX ) );
3093 GlobalPreferenceSystem().registerPreference( "SI_AxisColors1", make_property_string( g_xywindow_globals.AxisColorY ) );
3094 GlobalPreferenceSystem().registerPreference( "SI_AxisColors2", make_property_string( g_xywindow_globals.AxisColorZ ) );
3095 GlobalPreferenceSystem().registerPreference( "SI_Colors1", make_property_string( g_xywindow_globals.color_gridback ) );
3096 GlobalPreferenceSystem().registerPreference( "SI_Colors2", make_property_string( g_xywindow_globals.color_gridminor ) );
3097 GlobalPreferenceSystem().registerPreference( "SI_Colors3", make_property_string( g_xywindow_globals.color_gridmajor ) );
3098 GlobalPreferenceSystem().registerPreference( "SI_Colors6", make_property_string( g_xywindow_globals.color_gridblock ) );
3099 GlobalPreferenceSystem().registerPreference( "SI_Colors7", make_property_string( g_xywindow_globals.color_gridtext ) );
3100 GlobalPreferenceSystem().registerPreference( "SI_Colors8", make_property_string( g_xywindow_globals.color_brushes ) );
3101 GlobalPreferenceSystem().registerPreference( "SI_Colors9", make_property_string( g_xywindow_globals.color_viewname ) );
3102 GlobalPreferenceSystem().registerPreference( "SI_Colors10", make_property_string( g_xywindow_globals.color_clipper ) );
3103 GlobalPreferenceSystem().registerPreference( "SI_Colors11", make_property_string( g_xywindow_globals.color_selbrushes ) );
3108 GlobalPreferenceSystem().registerPreference( "XZVIS", make_property_string<ToggleShown_Bool>( g_xz_front_shown ) );
3109 GlobalPreferenceSystem().registerPreference( "YZVIS", make_property_string<ToggleShown_Bool>( g_yz_side_shown ) );
3111 Orthographic_registerPreferencesPage();
3112 Clipper_registerPreferencesPage();
3114 XYWnd::captureStates();
3115 GlobalEntityClassManager().attach( g_EntityClassMenu );
3118 void XYWindow_Destroy(){
3119 GlobalEntityClassManager().detach( g_EntityClassMenu );
3120 XYWnd::releaseStates();