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 <gtk/gtklabel.h>
38 #include <gtk/gtkmenuitem.h>
40 #include "generic/callback.h"
41 #include "string/string.h"
42 #include "stream/stringstream.h"
44 #include "eclasslib.h"
46 #include "moduleobserver.h"
48 #include "gtkutil/menu.h"
49 #include "gtkutil/container.h"
50 #include "gtkutil/widget.h"
51 #include "gtkutil/glwidget.h"
55 #include "brushmanip.h"
56 #include "selection.h"
58 #include "camwindow.h"
59 #include "texwindow.h"
60 #include "mainframe.h"
61 #include "preferences.h"
65 #include "windowobservers.h"
74 Vector3 m_ptClip; // the 3d point
83 m_ptClip[0] = m_ptClip[1] = m_ptClip[2] = 0.0;
99 /*! Draw clip/path point with rasterized number label */
100 void Draw(int num, float scale);
101 /*! Draw clip/path point with rasterized string label */
102 void Draw(const char *label, float scale);
105 VIEWTYPE g_clip_viewtype;
106 bool g_bSwitch = true;
107 bool g_clip_useCaulk = false;
111 ClipPoint* g_pMovingClip = 0;
113 /* Drawing clip points */
114 void ClipPoint::Draw(int num, float scale)
116 StringOutputStream label(4);
118 Draw(label.c_str(), scale);
121 void ClipPoint::Draw(const char *label, float scale)
125 glColor3fv(vector3_to_array(g_xywindow_globals.color_clipper));
127 glVertex3fv(vector3_to_array(m_ptClip));
131 float offset = 2.0f / scale;
134 glRasterPos3f (m_ptClip[0] + offset, m_ptClip[1] + offset, m_ptClip[2] + offset);
135 glCallLists (GLsizei(strlen(label)), GL_UNSIGNED_BYTE, label);
138 float fDiff(float f1, float f2)
146 inline double ClipPoint_Intersect(const ClipPoint& clip, const Vector3& point, VIEWTYPE viewtype, float scale)
148 int nDim1 = (viewtype == YZ) ? 1 : 0;
149 int nDim2 = (viewtype == XY) ? 1 : 2;
150 double screenDistanceSquared(vector2_length_squared(Vector2(fDiff(clip.m_ptClip[nDim1], point[nDim1]) * scale, fDiff(clip.m_ptClip[nDim2], point[nDim2]) * scale)));
151 if(screenDistanceSquared < 8*8)
153 return screenDistanceSquared;
158 inline void ClipPoint_testSelect(ClipPoint& clip, const Vector3& point, VIEWTYPE viewtype, float scale, double& bestDistance, ClipPoint*& bestClip)
162 double distance = ClipPoint_Intersect(clip, point, viewtype, scale);
163 if(distance < bestDistance)
165 bestDistance = distance;
171 inline ClipPoint* GlobalClipPoints_Find(const Vector3& point, VIEWTYPE viewtype, float scale)
173 double bestDistance = FLT_MAX;
174 ClipPoint* bestClip = 0;
175 ClipPoint_testSelect(g_Clip1, point, viewtype, scale, bestDistance, bestClip);
176 ClipPoint_testSelect(g_Clip2, point, viewtype, scale, bestDistance, bestClip);
177 ClipPoint_testSelect(g_Clip3, point, viewtype, scale, bestDistance, bestClip);
181 inline void GlobalClipPoints_Draw(float scale)
185 g_Clip1.Draw(1, scale);
187 g_Clip2.Draw(2, scale);
189 g_Clip3.Draw(3, scale);
192 inline bool GlobalClipPoints_valid()
194 return g_Clip1.Set() && g_Clip2.Set();
197 void PlanePointsFromClipPoints(Vector3 planepts[3], const AABB& bounds, int viewtype)
199 ASSERT_MESSAGE(GlobalClipPoints_valid(), "clipper points not initialised");
200 planepts[0] = g_Clip1.m_ptClip;
201 planepts[1] = g_Clip2.m_ptClip;
202 planepts[2] = g_Clip3.m_ptClip;
203 Vector3 maxs(vector3_added(bounds.origin, bounds.extents));
204 Vector3 mins(vector3_subtracted(bounds.origin, bounds.extents));
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
213 planepts[0][n] = maxs[n];
214 planepts[1][n] = maxs[n];
215 planepts[2][x] = g_Clip1.m_ptClip[x];
216 planepts[2][y] = g_Clip1.m_ptClip[y];
217 planepts[2][n] = mins[n];
221 planepts[0][n] = mins[n];
222 planepts[1][n] = mins[n];
223 planepts[2][x] = g_Clip1.m_ptClip[x];
224 planepts[2][y] = g_Clip1.m_ptClip[y];
225 planepts[2][n] = maxs[n];
233 if(!GlobalClipPoints_valid())
235 planepts[0] = Vector3(0, 0, 0);
236 planepts[1] = Vector3(0, 0, 0);
237 planepts[2] = Vector3(0, 0, 0);
238 Scene_BrushSetClipPlane(GlobalSceneGraph(), Plane3(0, 0, 0, 0));
242 AABB bounds(Vector3(0, 0, 0), Vector3(64, 64, 64));
243 PlanePointsFromClipPoints(planepts, bounds, g_clip_viewtype);
246 std::swap(planepts[0], planepts[1]);
248 Scene_BrushSetClipPlane(GlobalSceneGraph(), plane3_for_points(planepts[0], planepts[1], planepts[2]));
250 ClipperChangeNotify();
253 const char* Clip_getShader()
255 return g_clip_useCaulk ? "textures/common/caulk" : TextureBrowser_GetSelectedShader(GlobalTextureBrowser());
260 if (ClipMode() && GlobalClipPoints_valid())
263 AABB bounds(Vector3(0, 0, 0), Vector3(64, 64, 64));
264 PlanePointsFromClipPoints(planepts, bounds, g_clip_viewtype);
265 Scene_BrushSplitByPlane(GlobalSceneGraph(), planepts[0], planepts[1], planepts[2], Clip_getShader(), (!g_bSwitch) ? eFront : eBack);
270 ClipperChangeNotify();
276 if (ClipMode() && GlobalClipPoints_valid())
279 AABB bounds(Vector3(0, 0, 0), Vector3(64, 64, 64));
280 PlanePointsFromClipPoints(planepts, bounds, g_clip_viewtype);
281 Scene_BrushSplitByPlane(GlobalSceneGraph(), planepts[0], planepts[1], planepts[2], Clip_getShader(), eFrontAndBack);
286 ClipperChangeNotify();
292 g_bSwitch = !g_bSwitch;
294 ClipperChangeNotify();
297 void OnClipMode(bool enabled)
303 if(!enabled && g_pMovingClip)
309 ClipperChangeNotify();
314 return GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eClip;
317 void NewClipPoint(const Vector3& point)
319 if (g_Clip1.Set() == false)
321 g_Clip1.m_ptClip = point;
324 else if (g_Clip2.Set() == false)
326 g_Clip2.m_ptClip = point;
329 else if (g_Clip3.Set() == false)
331 g_Clip3.m_ptClip = point;
339 g_Clip1.m_ptClip = point;
344 ClipperChangeNotify();
349 struct xywindow_globals_private_t
353 // these are in the View > Show menu with Show coordinates
355 bool show_coordinates;
369 xywindow_globals_private_t() :
373 show_coordinates(true),
382 m_bCamXYUpdate(true),
390 xywindow_globals_t g_xywindow_globals;
391 xywindow_globals_private_t g_xywindow_globals_private;
393 const unsigned int RAD_NONE = 0x00;
394 const unsigned int RAD_SHIFT = 0x01;
395 const unsigned int RAD_ALT = 0x02;
396 const unsigned int RAD_CONTROL = 0x04;
397 const unsigned int RAD_PRESS = 0x08;
398 const unsigned int RAD_LBUTTON = 0x10;
399 const unsigned int RAD_MBUTTON = 0x20;
400 const unsigned int RAD_RBUTTON = 0x40;
402 inline ButtonIdentifier button_for_flags(unsigned int flags)
404 if(flags & RAD_LBUTTON)
406 if(flags & RAD_RBUTTON)
407 return c_buttonRight;
408 if(flags & RAD_MBUTTON)
409 return c_buttonMiddle;
410 return c_buttonInvalid;
413 inline ModifierFlags modifiers_for_flags(unsigned int flags)
415 ModifierFlags modifiers = c_modifierNone;
416 if(flags & RAD_SHIFT)
417 modifiers |= c_modifierShift;
418 if(flags & RAD_CONTROL)
419 modifiers |= c_modifierControl;
421 modifiers |= c_modifierAlt;
425 inline unsigned int buttons_for_event_button(GdkEventButton* event)
427 unsigned int flags = 0;
429 switch (event->button)
431 case 1: flags |= RAD_LBUTTON; break;
432 case 2: flags |= RAD_MBUTTON; break;
433 case 3: flags |= RAD_RBUTTON; break;
436 if ((event->state & GDK_CONTROL_MASK) != 0)
437 flags |= RAD_CONTROL;
439 if ((event->state & GDK_SHIFT_MASK) != 0)
442 if((event->state & GDK_MOD1_MASK) != 0)
448 inline unsigned int buttons_for_state(guint state)
450 unsigned int flags = 0;
452 if ((state & GDK_BUTTON1_MASK) != 0)
453 flags |= RAD_LBUTTON;
455 if ((state & GDK_BUTTON2_MASK) != 0)
456 flags |= RAD_MBUTTON;
458 if ((state & GDK_BUTTON3_MASK) != 0)
459 flags |= RAD_RBUTTON;
461 if ((state & GDK_CONTROL_MASK) != 0)
462 flags |= RAD_CONTROL;
464 if ((state & GDK_SHIFT_MASK) != 0)
467 if ((state & GDK_MOD1_MASK) != 0)
474 void XYWnd::SetScale(float f)
482 void XYWnd_ZoomIn(XYWnd* xy)
484 float max_scale = 64;
485 float scale = xy->Scale() * 5.0f / 4.0f;
486 if(scale > max_scale)
488 if(xy->Scale() != max_scale)
490 xy->SetScale (max_scale);
500 // NOTE: the zoom out factor is 4/5, we could think about customizing it
501 // we don't go below a zoom factor corresponding to 10% of the max world size
502 // (this has to be computed against the window size)
503 void XYWnd_ZoomOut(XYWnd* xy)
505 float min_scale = MIN(xy->Width(),xy->Height()) / ( 1.1f * (g_MaxWorldCoord-g_MinWorldCoord));
506 float scale = xy->Scale() * 4.0f / 5.0f;
507 if(scale < min_scale)
509 if(xy->Scale() != min_scale)
511 xy->SetScale (min_scale);
520 VIEWTYPE GlobalXYWnd_getCurrentViewType()
522 ASSERT_NOTNULL(g_pParentWnd);
523 ASSERT_NOTNULL(g_pParentWnd->ActiveXY());
524 return g_pParentWnd->ActiveXY()->GetViewType();
527 // =============================================================================
530 bool g_bCrossHairs = false;
532 GtkMenu* XYWnd::m_mnuDrop = 0;
534 // this is disabled, and broken
535 // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=394
540 width = g_pParentWnd->ActiveXY()->Width();
541 height = g_pParentWnd->ActiveXY()->Height();
543 const char* filename;
545 filename = file_dialog(GTK_WIDGET(MainFrame_getWindow()), FALSE, "Save Image", 0, FILTER_BMP);
549 g_pParentWnd->ActiveXY()->MakeCurrent();
550 img = (unsigned char*)malloc (width*height*3);
551 glReadPixels (0,0,width,height,GL_RGB,GL_UNSIGNED_BYTE,img);
554 fp = fopen(filename, "wb");
558 unsigned long cmap, bfSize;
562 bfSize = 54 + width*height*3;
564 long byteswritten = 0;
565 long pixoff = 54 + cmap*4;
567 char m1 ='B', m2 ='M';
568 fwrite(&m1, 1, 1, fp); byteswritten++; // B
569 fwrite(&m2, 1, 1, fp); byteswritten++; // M
570 fwrite(&bfSize, 4, 1, fp); byteswritten+=4;// bfSize
571 fwrite(&res, 2, 1, fp); byteswritten+=2;// bfReserved1
572 fwrite(&res, 2, 1, fp); byteswritten+=2;// bfReserved2
573 fwrite(&pixoff, 4, 1, fp); byteswritten+=4;// bfOffBits
575 unsigned long biSize = 40, compress = 0, size = 0;
577 unsigned short planes = 1;
578 fwrite(&biSize, 4, 1, fp); byteswritten+=4;// biSize
579 fwrite(&width, 4, 1, fp); byteswritten+=4;// biWidth
580 fwrite(&height, 4, 1, fp); byteswritten+=4;// biHeight
581 fwrite(&planes, 2, 1, fp); byteswritten+=2;// biPlanes
582 fwrite(&bits, 2, 1, fp); byteswritten+=2;// biBitCount
583 fwrite(&compress, 4, 1, fp);byteswritten+=4;// biCompression
584 fwrite(&size, 4, 1, fp); byteswritten+=4;// biSizeImage
585 fwrite(&pixels, 4, 1, fp); byteswritten+=4;// biXPelsPerMeter
586 fwrite(&pixels, 4, 1, fp); byteswritten+=4;// biYPelsPerMeter
587 fwrite(&cmap, 4, 1, fp); byteswritten+=4;// biClrUsed
588 fwrite(&cmap, 4, 1, fp); byteswritten+=4;// biClrImportant
590 unsigned long widthDW = (((width*24) + 31) / 32 * 4);
591 long row, row_size = width*3;
592 for (row = 0; row < height; row++)
594 unsigned char* buf = img+row*row_size;
598 for (col = 0; col < row_size; col += 3)
600 putc(buf[col+2], fp);
601 putc(buf[col+1], fp);
604 byteswritten += row_size;
607 for (count = row_size; count < widthDW; count++)
609 putc(0, fp); // dummy
624 Timer g_chasemouse_timer;
626 void XYWnd::ChaseMouse()
628 float multiplier = g_chasemouse_timer.elapsed_msec() / 10.0f;
629 Scroll(float_to_integer(multiplier * m_chasemouse_delta_x), float_to_integer(multiplier * -m_chasemouse_delta_y));
631 //globalOutputStream() << "chasemouse: multiplier=" << multiplier << " x=" << m_chasemouse_delta_x << " y=" << m_chasemouse_delta_y << '\n';
633 XY_MouseMoved(m_chasemouse_current_x, m_chasemouse_current_y , getButtonState());
634 g_chasemouse_timer.start();
637 gboolean xywnd_chasemouse(gpointer data)
639 reinterpret_cast<XYWnd*>(data)->ChaseMouse();
643 inline const int& min_int(const int& left, const int& right)
645 return std::min(left, right);
648 bool XYWnd::chaseMouseMotion(int pointx, int pointy)
650 m_chasemouse_delta_x = 0;
651 m_chasemouse_delta_y = 0;
653 if (g_xywindow_globals_private.m_bChaseMouse && getButtonState() == RAD_LBUTTON)
655 const int epsilon = 16;
657 if (pointx < epsilon)
659 m_chasemouse_delta_x = std::max(pointx, 0) - epsilon;
661 else if ((pointx - m_nWidth) > -epsilon)
663 m_chasemouse_delta_x = min_int((pointx - m_nWidth), 0) + epsilon;
666 if (pointy < epsilon)
668 m_chasemouse_delta_y = std::max(pointy, 0) - epsilon;
670 else if ((pointy - m_nHeight) > -epsilon)
672 m_chasemouse_delta_y = min_int((pointy - m_nHeight), 0) + epsilon;
675 if(m_chasemouse_delta_y != 0 || m_chasemouse_delta_x != 0)
677 //globalOutputStream() << "chasemouse motion: x=" << pointx << " y=" << pointy << "... ";
678 m_chasemouse_current_x = pointx;
679 m_chasemouse_current_y = pointy;
680 if(m_chasemouse_handler == 0)
682 //globalOutputStream() << "chasemouse timer start... ";
683 g_chasemouse_timer.start();
684 m_chasemouse_handler = g_idle_add(xywnd_chasemouse, this);
690 if(m_chasemouse_handler != 0)
692 //globalOutputStream() << "chasemouse cancel\n";
693 g_source_remove(m_chasemouse_handler);
694 m_chasemouse_handler = 0;
700 if(m_chasemouse_handler != 0)
702 //globalOutputStream() << "chasemouse cancel\n";
703 g_source_remove(m_chasemouse_handler);
704 m_chasemouse_handler = 0;
710 // =============================================================================
712 Shader* XYWnd::m_state_selected = 0;
714 void xy_update_xor_rectangle(XYWnd& self, rect_t area)
716 if(GTK_WIDGET_VISIBLE(self.GetWidget()))
718 self.m_XORRectangle.set(rectangle_from_area(area.min, area.max, self.Width(), self.Height()));
722 gboolean xywnd_button_press(GtkWidget* widget, GdkEventButton* event, XYWnd* xywnd)
724 if(event->type == GDK_BUTTON_PRESS)
726 xywnd->XY_MouseDown(static_cast<int>(event->x), static_cast<int>(event->y), buttons_for_event_button(event));
731 gboolean xywnd_button_release(GtkWidget* widget, GdkEventButton* event, XYWnd* xywnd)
733 if(event->type == GDK_BUTTON_RELEASE)
735 xywnd->XY_MouseUp(static_cast<int>(event->x), static_cast<int>(event->y), buttons_for_event_button(event));
740 void xywnd_motion(gdouble x, gdouble y, guint state, void* data)
742 if(reinterpret_cast<XYWnd*>(data)->chaseMouseMotion(static_cast<int>(x), static_cast<int>(y)))
746 reinterpret_cast<XYWnd*>(data)->XY_MouseMoved(static_cast<int>(x), static_cast<int>(y), buttons_for_state(state));
749 gboolean xywnd_wheel_scroll(GtkWidget* widget, GdkEventScroll* event, XYWnd* xywnd)
751 if(event->direction == GDK_SCROLL_UP)
755 else if(event->direction == GDK_SCROLL_DOWN)
757 XYWnd_ZoomOut(xywnd);
762 gboolean xywnd_size_allocate(GtkWidget* widget, GtkAllocation* allocation, XYWnd* xywnd)
764 xywnd->m_nWidth = allocation->width;
765 xywnd->m_nHeight = allocation->height;
766 xywnd->updateProjection();
767 xywnd->m_window_observer->onSizeChanged(xywnd->Width(), xywnd->Height());
771 gboolean xywnd_expose(GtkWidget* widget, GdkEventExpose* event, XYWnd* xywnd)
773 if(glwidget_make_current(xywnd->GetWidget()) != FALSE)
775 if(Map_Valid(g_map) && ScreenUpdates_Enabled())
777 GlobalOpenGL_debugAssertNoErrors();
779 GlobalOpenGL_debugAssertNoErrors();
781 xywnd->m_XORRectangle.set(rectangle_t());
783 glwidget_swap_buffers(xywnd->GetWidget());
789 void XYWnd_CameraMoved(XYWnd& xywnd)
791 if(g_xywindow_globals_private.m_bCamXYUpdate)
798 m_gl_widget(glwidget_new(FALSE)),
799 m_deferredDraw(WidgetQueueDrawCaller(*m_gl_widget)),
800 m_deferred_motion(xywnd_motion, this),
802 m_window_observer(NewWindowObserver()),
803 m_XORRectangle(m_gl_widget),
804 m_chasemouse_handler(0)
809 m_bNewBrushDrag = false;
810 m_move_started = false;
811 m_zoom_started = false;
822 m_entityCreate = false;
826 GlobalWindowObservers_add(m_window_observer);
827 GlobalWindowObservers_connectWidget(m_gl_widget);
829 m_window_observer->setRectangleDrawCallback(ReferenceCaller1<XYWnd, rect_t, xy_update_xor_rectangle>(*this));
830 m_window_observer->setView(m_view);
832 gtk_widget_ref(m_gl_widget);
834 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);
835 GTK_WIDGET_SET_FLAGS(m_gl_widget, GTK_CAN_FOCUS);
837 m_sizeHandler = g_signal_connect(G_OBJECT(m_gl_widget), "size_allocate", G_CALLBACK(xywnd_size_allocate), this);
838 m_exposeHandler = g_signal_connect(G_OBJECT(m_gl_widget), "expose_event", G_CALLBACK(xywnd_expose), this);
840 g_signal_connect(G_OBJECT(m_gl_widget), "button_press_event", G_CALLBACK(xywnd_button_press), this);
841 g_signal_connect(G_OBJECT(m_gl_widget), "button_release_event", G_CALLBACK(xywnd_button_release), this);
842 g_signal_connect(G_OBJECT(m_gl_widget), "motion_notify_event", G_CALLBACK(DeferredMotion::gtk_motion), &m_deferred_motion);
844 g_signal_connect(G_OBJECT(m_gl_widget), "scroll_event", G_CALLBACK(xywnd_wheel_scroll), this);
846 Map_addValidCallback(g_map, DeferredDrawOnMapValidChangedCaller(m_deferredDraw));
851 AddSceneChangeCallback(ReferenceCaller<XYWnd, &XYWnd_Update>(*this));
852 AddCameraMovedCallback(ReferenceCaller<XYWnd, &XYWnd_CameraMoved>(*this));
854 PressedButtons_connect(g_pressedButtons, m_gl_widget);
861 gtk_widget_destroy(GTK_WIDGET(m_mnuDrop));
865 g_signal_handler_disconnect(G_OBJECT(m_gl_widget), m_sizeHandler);
866 g_signal_handler_disconnect(G_OBJECT(m_gl_widget), m_exposeHandler);
868 gtk_widget_unref(m_gl_widget);
870 m_window_observer->release();
873 void XYWnd::captureStates()
875 m_state_selected = GlobalShaderCache().capture("$XY_OVERLAY");
878 void XYWnd::releaseStates()
880 GlobalShaderCache().release("$XY_OVERLAY");
883 const Vector3& XYWnd::GetOrigin()
888 void XYWnd::SetOrigin(const Vector3& origin)
894 void XYWnd::Scroll(int x, int y)
896 int nDim1 = (m_viewType == YZ) ? 1 : 0;
897 int nDim2 = (m_viewType == XY) ? 1 : 2;
898 m_vOrigin[nDim1] += x / m_fScale;
899 m_vOrigin[nDim2] += y / m_fScale;
904 unsigned int Clipper_buttons()
909 void XYWnd::DropClipPoint(int pointx, int pointy)
913 XY_ToPoint(pointx, pointy, point);
917 g_clip_viewtype = static_cast<VIEWTYPE>(GetViewType());
918 int nDim = (g_clip_viewtype == YZ ) ? nDim = 0 : ( (g_clip_viewtype == XZ) ? nDim = 1 : nDim = 2 );
919 point[nDim] = mid[nDim];
920 vector3_snap(point, GetGridSize());
924 void XYWnd::Clipper_OnLButtonDown(int x, int y)
926 Vector3 mousePosition;
927 XY_ToPoint(x, y , mousePosition);
928 g_pMovingClip = GlobalClipPoints_Find(mousePosition, (VIEWTYPE)m_viewType, m_fScale);
935 void XYWnd::Clipper_OnLButtonUp(int x, int y)
943 void XYWnd::Clipper_OnMouseMoved(int x, int y)
947 XY_ToPoint(x, y , g_pMovingClip->m_ptClip);
948 XY_SnapToGrid(g_pMovingClip->m_ptClip);
950 ClipperChangeNotify();
954 void XYWnd::Clipper_Crosshair_OnMouseMoved(int x, int y)
956 Vector3 mousePosition;
957 XY_ToPoint(x, y , mousePosition);
958 if(ClipMode() && GlobalClipPoints_Find(mousePosition, (VIEWTYPE)m_viewType, m_fScale) != 0)
961 cursor = gdk_cursor_new (GDK_CROSSHAIR);
962 gdk_window_set_cursor (m_gl_widget->window, cursor);
963 gdk_cursor_unref (cursor);
967 gdk_window_set_cursor (m_gl_widget->window, 0);
971 unsigned int MoveCamera_buttons()
973 return RAD_CONTROL | (g_glwindow_globals.m_nMouseType == ETwoButton ? RAD_RBUTTON : RAD_MBUTTON);
976 void XYWnd_PositionCamera(XYWnd* xywnd, int x, int y, CamWnd& camwnd)
978 Vector3 origin(Camera_getOrigin(camwnd));
979 xywnd->XY_ToPoint(x, y, origin);
980 xywnd->XY_SnapToGrid(origin);
981 Camera_setOrigin(camwnd, origin);
984 unsigned int OrientCamera_buttons()
986 if(g_glwindow_globals.m_nMouseType == ETwoButton)
987 return RAD_RBUTTON | RAD_SHIFT | RAD_CONTROL;
991 void XYWnd_OrientCamera(XYWnd* xywnd, int x, int y, CamWnd& camwnd)
993 Vector3 point = g_vector3_identity;
994 xywnd->XY_ToPoint(x, y, point);
995 xywnd->XY_SnapToGrid(point);
996 vector3_subtract(point, Camera_getOrigin(camwnd));
998 int n1 = (xywnd->GetViewType() == XY) ? 1 : 2;
999 int n2 = (xywnd->GetViewType() == YZ) ? 1 : 0;
1000 int nAngle = (xywnd->GetViewType() == XY) ? CAMERA_YAW : CAMERA_PITCH;
1001 if (point[n1] || point[n2])
1003 Vector3 angles(Camera_getAngles(camwnd));
1004 angles[nAngle] = static_cast<float>(radians_to_degrees(atan2 (point[n1], point[n2])));
1005 Camera_setAngles(camwnd, angles);
1014 unsigned int NewBrushDrag_buttons()
1019 void XYWnd::NewBrushDrag_Begin(int x, int y)
1022 m_nNewBrushPressx = x;
1023 m_nNewBrushPressy = y;
1025 m_bNewBrushDrag = true;
1026 GlobalUndoSystem().start();
1029 void XYWnd::NewBrushDrag_End(int x, int y)
1031 if(m_NewBrushDrag != 0)
1033 GlobalUndoSystem().finish("brushDragNew");
1037 void XYWnd::NewBrushDrag(int x, int y)
1040 XY_ToPoint(m_nNewBrushPressx, m_nNewBrushPressy, mins);
1041 XY_SnapToGrid(mins);
1042 XY_ToPoint(x, y, maxs);
1043 XY_SnapToGrid(maxs);
1045 int nDim = (m_viewType == XY) ? 2 : (m_viewType == YZ) ? 0 : 1;
1047 mins[nDim] = float_snapped(Select_getWorkZone().d_work_min[nDim], GetGridSize());
1048 maxs[nDim] = float_snapped(Select_getWorkZone().d_work_max[nDim], GetGridSize());
1050 if (maxs[nDim] <= mins[nDim])
1051 maxs[nDim] = mins[nDim] + GetGridSize();
1053 for(int i=0 ; i<3 ; i++)
1055 if (mins[i] == maxs[i])
1056 return; // don't create a degenerate brush
1057 if (mins[i] > maxs[i])
1059 float temp = mins[i];
1065 if(m_NewBrushDrag == 0)
1067 NodeSmartReference node(GlobalBrushCreator().createBrush());
1068 Node_getTraversable(Map_FindOrInsertWorldspawn(g_map))->insert(node);
1070 scene::Path brushpath(makeReference(GlobalSceneGraph().root()));
1071 brushpath.push(makeReference(*Map_GetWorldspawn(g_map)));
1072 brushpath.push(makeReference(node.get()));
1073 selectPath(brushpath, true);
1075 m_NewBrushDrag = node.get_pointer();
1078 Scene_BrushResize_Selected(GlobalSceneGraph(), aabb_for_minmax(mins, maxs), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()));
1081 void entitycreate_activated(GtkWidget* item)
1083 g_pParentWnd->ActiveXY()->OnEntityCreate(gtk_label_get_text(GTK_LABEL(GTK_BIN(item)->child)));
1086 void EntityClassMenu_addItem(GtkMenu* menu, const char* name)
1088 GtkMenuItem* item = GTK_MENU_ITEM(gtk_menu_item_new_with_label(name));
1089 g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(entitycreate_activated), item);
1090 gtk_widget_show(GTK_WIDGET(item));
1091 menu_add_item(menu, item);
1094 class EntityClassMenuInserter : public EntityClassVisitor
1096 typedef std::pair<GtkMenu*, CopiedString> MenuPair;
1097 typedef std::vector<MenuPair> MenuStack;
1099 CopiedString m_previous;
1101 EntityClassMenuInserter(GtkMenu* menu)
1104 m_stack.push_back(MenuPair(menu, ""));
1106 ~EntityClassMenuInserter()
1108 if(!string_empty(m_previous.c_str()))
1110 addItem(m_previous.c_str(), "");
1113 void visit(EntityClass* e)
1115 ASSERT_MESSAGE(!string_empty(e->name()), "entity-class has no name");
1116 if(!string_empty(m_previous.c_str()))
1118 addItem(m_previous.c_str(), e->name());
1120 m_previous = e->name();
1122 void pushMenu(const CopiedString& name)
1124 GtkMenuItem* item = GTK_MENU_ITEM(gtk_menu_item_new_with_label(name.c_str()));
1125 gtk_widget_show(GTK_WIDGET(item));
1126 container_add_widget(GTK_CONTAINER(m_stack.back().first), GTK_WIDGET(item));
1128 GtkMenu* submenu = GTK_MENU(gtk_menu_new());
1129 gtk_menu_item_set_submenu(item, GTK_WIDGET(submenu));
1131 m_stack.push_back(MenuPair(submenu, name));
1137 void addItem(const char* name, const char* next)
1139 const char* underscore = strchr(name, '_');
1141 if(underscore != 0 && underscore != name)
1143 bool nextEqual = string_equal_n(name, next, (underscore + 1) - name);
1144 const char* parent = m_stack.back().second.c_str();
1146 if(!string_empty(parent)
1147 && string_length(parent) == std::size_t(underscore - name)
1148 && string_equal_n(name, parent, underscore - name)) // this is a child
1153 if(m_stack.size() == 2)
1157 pushMenu(CopiedString(StringRange(name, underscore)));
1159 else if(m_stack.size() == 2)
1164 else if(m_stack.size() == 2)
1169 EntityClassMenu_addItem(m_stack.back().first, name);
1173 void XYWnd::OnContextMenu()
1175 if (g_xywindow_globals.m_bRightClick == false)
1178 if (m_mnuDrop == 0) // first time, load it up
1180 GtkMenu* menu = m_mnuDrop = GTK_MENU(gtk_menu_new());
1182 EntityClassMenuInserter inserter(menu);
1183 GlobalEntityClassManager().forEach(inserter);
1186 gtk_menu_popup(m_mnuDrop, 0, 0, 0, 0, 1, GDK_CURRENT_TIME);
1189 FreezePointer g_xywnd_freezePointer;
1191 unsigned int Move_buttons()
1196 void XYWnd_moveDelta(int x, int y, unsigned int state, void* data)
1198 reinterpret_cast<XYWnd*>(data)->EntityCreate_MouseMove(x, y);
1199 reinterpret_cast<XYWnd*>(data)->Scroll(-x, y);
1202 gboolean XYWnd_Move_focusOut(GtkWidget* widget, GdkEventFocus* event, XYWnd* xywnd)
1208 void XYWnd::Move_Begin()
1214 m_move_started = true;
1215 g_xywnd_freezePointer.freeze_pointer(m_parent != 0 ? m_parent : MainFrame_getWindow(), XYWnd_moveDelta, this);
1216 m_move_focusOut = g_signal_connect(G_OBJECT(m_gl_widget), "focus_out_event", G_CALLBACK(XYWnd_Move_focusOut), this);
1219 void XYWnd::Move_End()
1221 m_move_started = false;
1222 g_xywnd_freezePointer.unfreeze_pointer(m_parent != 0 ? m_parent : MainFrame_getWindow());
1223 g_signal_handler_disconnect(G_OBJECT(m_gl_widget), m_move_focusOut);
1226 unsigned int Zoom_buttons()
1228 return RAD_RBUTTON | RAD_SHIFT;
1233 void XYWnd_zoomDelta(int x, int y, unsigned int state, void* data)
1239 while(abs(g_dragZoom) > 8)
1243 XYWnd_ZoomOut(reinterpret_cast<XYWnd*>(data));
1248 XYWnd_ZoomIn(reinterpret_cast<XYWnd*>(data));
1255 gboolean XYWnd_Zoom_focusOut(GtkWidget* widget, GdkEventFocus* event, XYWnd* xywnd)
1261 void XYWnd::Zoom_Begin()
1267 m_zoom_started = true;
1269 g_xywnd_freezePointer.freeze_pointer(m_parent != 0 ? m_parent : MainFrame_getWindow(), XYWnd_zoomDelta, this);
1270 m_zoom_focusOut = g_signal_connect(G_OBJECT(m_gl_widget), "focus_out_event", G_CALLBACK(XYWnd_Zoom_focusOut), this);
1273 void XYWnd::Zoom_End()
1275 m_zoom_started = false;
1276 g_xywnd_freezePointer.unfreeze_pointer(m_parent != 0 ? m_parent : MainFrame_getWindow());
1277 g_signal_handler_disconnect(G_OBJECT(m_gl_widget), m_zoom_focusOut);
1280 // makes sure the selected brush or camera is in view
1281 void XYWnd::PositionView(const Vector3& position)
1283 int nDim1 = (m_viewType == YZ) ? 1 : 0;
1284 int nDim2 = (m_viewType == XY) ? 1 : 2;
1286 m_vOrigin[nDim1] = position[nDim1];
1287 m_vOrigin[nDim2] = position[nDim2];
1291 XYWnd_Update(*this);
1294 void XYWnd::SetViewType(VIEWTYPE viewType)
1296 m_viewType = viewType;
1301 gtk_window_set_title(m_parent, ViewType_getTitle(m_viewType));
1306 inline WindowVector WindowVector_forInteger(int x, int y)
1308 return WindowVector(static_cast<float>(x), static_cast<float>(y));
1311 void XYWnd::XY_MouseDown (int x, int y, unsigned int buttons)
1313 g_pParentWnd->SetActiveXY(this);
1315 ButtonState_onMouseDown(buttons);
1317 if(buttons == Move_buttons())
1320 EntityCreate_MouseDown(x, y);
1322 else if(buttons == Zoom_buttons())
1326 else if(ClipMode() && buttons == Clipper_buttons())
1328 Clipper_OnLButtonDown(x, y);
1330 else if(buttons == NewBrushDrag_buttons() && GlobalSelectionSystem().countSelected() == 0)
1332 NewBrushDrag_Begin(x, y);
1334 // control mbutton = move camera
1335 else if (buttons == MoveCamera_buttons())
1337 XYWnd_PositionCamera(this, x, y, *g_pParentWnd->GetCamWnd());
1339 // mbutton = angle camera
1340 else if(buttons == OrientCamera_buttons())
1342 XYWnd_OrientCamera(this, x, y, *g_pParentWnd->GetCamWnd());
1346 m_window_observer->onMouseDown(WindowVector_forInteger(x, y), button_for_flags(buttons), modifiers_for_flags(buttons));
1350 void XYWnd::XY_MouseUp(int x, int y, unsigned int buttons)
1355 EntityCreate_MouseUp(x, y);
1357 else if(m_zoom_started)
1361 else if (ClipMode() && buttons == Clipper_buttons())
1363 Clipper_OnLButtonUp(x, y);
1365 else if (m_bNewBrushDrag)
1367 m_bNewBrushDrag = false;
1368 NewBrushDrag_End(x, y);
1372 m_window_observer->onMouseUp(WindowVector_forInteger(x, y), button_for_flags(buttons), modifiers_for_flags(buttons));
1375 ButtonState_onMouseUp(buttons);
1378 void XYWnd::XY_MouseMoved (int x, int y, unsigned int buttons)
1380 // rbutton = drag xy origin
1385 else if(m_zoom_started)
1389 else if (ClipMode() && g_pMovingClip != 0)
1391 Clipper_OnMouseMoved(x, y);
1393 // lbutton without selection = drag new brush
1394 else if (m_bNewBrushDrag)
1399 // control mbutton = move camera
1400 else if (getButtonState() == MoveCamera_buttons())
1402 XYWnd_PositionCamera(this, x, y, *g_pParentWnd->GetCamWnd());
1405 // mbutton = angle camera
1406 else if (getButtonState() == OrientCamera_buttons())
1408 XYWnd_OrientCamera(this, x, y, *g_pParentWnd->GetCamWnd());
1413 m_window_observer->onMouseMotion(WindowVector_forInteger(x, y), modifiers_for_flags(buttons));
1415 m_mousePosition[0] = m_mousePosition[1] = m_mousePosition[2] = 0.0;
1416 XY_ToPoint(x, y , m_mousePosition);
1417 XY_SnapToGrid(m_mousePosition);
1419 StringOutputStream status(64);
1420 status << "x:: " << FloatFormat(m_mousePosition[0], 6, 1)
1421 << " y:: " << FloatFormat(m_mousePosition[1], 6, 1)
1422 << " z:: " << FloatFormat(m_mousePosition[2], 6, 1);
1423 g_pParentWnd->SetStatusText(g_pParentWnd->m_position_status, status.c_str());
1427 XYWnd_Update(*this);
1430 Clipper_Crosshair_OnMouseMoved(x, y);
1434 void XYWnd::EntityCreate_MouseDown(int x, int y)
1436 m_entityCreate = true;
1437 m_entityCreate_x = x;
1438 m_entityCreate_y = y;
1441 void XYWnd::EntityCreate_MouseMove(int x, int y)
1443 if(m_entityCreate && (m_entityCreate_x != x || m_entityCreate_y != y))
1445 m_entityCreate = false;
1449 void XYWnd::EntityCreate_MouseUp(int x, int y)
1453 m_entityCreate = false;
1458 inline float screen_normalised(int pos, unsigned int size)
1460 return ((2.0f * pos) / size) - 1.0f;
1463 inline float normalised_to_world(float normalised, float world_origin, float normalised2world_scale)
1465 return world_origin + normalised * normalised2world_scale;
1469 // TTimo: watch it, this doesn't init one of the 3 coords
1470 void XYWnd::XY_ToPoint (int x, int y, Vector3& point)
1472 float normalised2world_scale_x = m_nWidth / 2 / m_fScale;
1473 float normalised2world_scale_y = m_nHeight / 2 / m_fScale;
1474 if (m_viewType == XY)
1476 point[0] = normalised_to_world(screen_normalised(x, m_nWidth), m_vOrigin[0], normalised2world_scale_x);
1477 point[1] = normalised_to_world(-screen_normalised(y, m_nHeight), m_vOrigin[1], normalised2world_scale_y);
1479 else if (m_viewType == YZ)
1481 point[1] = normalised_to_world(screen_normalised(x, m_nWidth), m_vOrigin[1], normalised2world_scale_x);
1482 point[2] = normalised_to_world(-screen_normalised(y, m_nHeight), m_vOrigin[2], normalised2world_scale_y);
1486 point[0] = normalised_to_world(screen_normalised(x, m_nWidth), m_vOrigin[0], normalised2world_scale_x);
1487 point[2] = normalised_to_world(-screen_normalised(y, m_nHeight), m_vOrigin[2], normalised2world_scale_y);
1491 void XYWnd::XY_SnapToGrid(Vector3& point)
1493 if (m_viewType == XY)
1495 point[0] = float_snapped(point[0], GetGridSize());
1496 point[1] = float_snapped(point[1], GetGridSize());
1498 else if (m_viewType == YZ)
1500 point[1] = float_snapped(point[1], GetGridSize());
1501 point[2] = float_snapped(point[2], GetGridSize());
1505 point[0] = float_snapped(point[0], GetGridSize());
1506 point[2] = float_snapped(point[2], GetGridSize());
1511 ============================================================================
1515 ============================================================================
1524 double two_to_the_power(int power)
1526 return pow(2.0f, power);
1529 void XYWnd::XY_DrawGrid()
1531 float x, y, xb, xe, yb, ye;
1534 float step, minor_step, stepx, stepy;
1535 step = minor_step = stepx = stepy = GetGridSize();
1537 int minor_power = Grid_getPower();
1540 while((minor_step * m_fScale) <= 4.0f) // make sure minor grid spacing is at least 4 pixels on the screen
1545 int power = minor_power;
1546 while((power % 3) != 0 || (step * m_fScale) <= 32.0f) // make sure major grid spacing is at least 32 pixels on the screen
1549 step = float(two_to_the_power(power));
1551 mask = (1 << (power - minor_power)) - 1;
1552 while ((stepx * m_fScale) <= 32.0f) // text step x must be at least 32
1554 while ((stepy * m_fScale) <= 32.0f) // text step y must be at least 32
1558 glDisable(GL_TEXTURE_2D);
1559 glDisable(GL_TEXTURE_1D);
1560 glDisable(GL_DEPTH_TEST);
1561 glDisable(GL_BLEND);
1564 w = (m_nWidth / 2 / m_fScale);
1565 h = (m_nHeight / 2 / m_fScale);
1567 int nDim1 = (m_viewType == YZ) ? 1 : 0;
1568 int nDim2 = (m_viewType == XY) ? 1 : 2;
1570 xb = m_vOrigin[nDim1] - w;
1571 if (xb < region_mins[nDim1])
1572 xb = region_mins[nDim1];
1573 xb = step * floor (xb/step);
1575 xe = m_vOrigin[nDim1] + w;
1576 if (xe > region_maxs[nDim1])
1577 xe = region_maxs[nDim1];
1578 xe = step * ceil (xe/step);
1580 yb = m_vOrigin[nDim2] - h;
1581 if (yb < region_mins[nDim2])
1582 yb = region_mins[nDim2];
1583 yb = step * floor (yb/step);
1585 ye = m_vOrigin[nDim2] + h;
1586 if (ye > region_maxs[nDim2])
1587 ye = region_maxs[nDim2];
1588 ye = step * ceil (ye/step);
1590 #define COLORS_DIFFER(a,b) \
1591 ((a)[0] != (b)[0] || \
1592 (a)[1] != (b)[1] || \
1596 // draw minor blocks
1597 if (g_xywindow_globals_private.d_showgrid)
1599 if (COLORS_DIFFER(g_xywindow_globals.color_gridminor, g_xywindow_globals.color_gridback))
1601 glColor3fv(vector3_to_array(g_xywindow_globals.color_gridminor));
1605 for (x = xb ; x < xe ; x += minor_step, ++i)
1614 for (y = yb ; y < ye ; y += minor_step, ++i)
1625 // draw major blocks
1626 if (COLORS_DIFFER(g_xywindow_globals.color_gridmajor, g_xywindow_globals.color_gridback))
1628 glColor3fv(vector3_to_array(g_xywindow_globals.color_gridmajor));
1631 for (x=xb ; x<=xe ; x+=step)
1636 for (y=yb ; y<=ye ; y+=step)
1645 // draw coordinate text if needed
1646 if ( g_xywindow_globals_private.show_coordinates)
1648 glColor3fv(vector3_to_array(g_xywindow_globals.color_gridtext));
1649 float offx = m_vOrigin[nDim2] + h - 6 / m_fScale, offy = m_vOrigin[nDim1] - w + 1 / m_fScale;
1650 for (x = xb - fmod(xb, stepx); x <= xe ; x += stepx)
1652 glRasterPos2f (x, offx);
1653 sprintf (text, "%g", x);
1654 GlobalOpenGL().drawString(text);
1656 for (y = yb - fmod(yb, stepy); y <= ye ; y += stepy)
1658 glRasterPos2f (offy, y);
1659 sprintf (text, "%g", y);
1660 GlobalOpenGL().drawString(text);
1664 glColor3fv(vector3_to_array(g_xywindow_globals.color_viewname));
1666 // we do this part (the old way) only if show_axis is disabled
1667 if (!g_xywindow_globals_private.show_axis)
1669 glRasterPos2f ( m_vOrigin[nDim1] - w + 35 / m_fScale, m_vOrigin[nDim2] + h - 20 / m_fScale );
1671 GlobalOpenGL().drawString(ViewType_getTitle(m_viewType));
1675 if ( g_xywindow_globals_private.show_axis)
1677 const char g_AxisName[3] = { 'X', 'Y', 'Z' };
1679 const Vector3& colourX = (m_viewType == YZ) ? g_xywindow_globals.AxisColorY : g_xywindow_globals.AxisColorX;
1680 const Vector3& colourY = (m_viewType == XY) ? g_xywindow_globals.AxisColorY : g_xywindow_globals.AxisColorZ;
1682 // draw two lines with corresponding axis colors to highlight current view
1683 // horizontal line: nDim1 color
1685 glBegin( GL_LINES );
1686 glColor3fv (vector3_to_array(colourX));
1687 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1688 glVertex2f( m_vOrigin[nDim1] - w + 65 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1690 glVertex2f( 32 / m_fScale, 0 );
1691 glColor3fv (vector3_to_array(colourY));
1692 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1693 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 20 / m_fScale );
1695 glVertex2f( 0, 32 / m_fScale );
1698 // now print axis symbols
1699 glColor3fv (vector3_to_array(colourX));
1700 glRasterPos2f ( m_vOrigin[nDim1] - w + 55 / m_fScale, m_vOrigin[nDim2] + h - 55 / m_fScale );
1701 GlobalOpenGL().drawChar(g_AxisName[nDim1]);
1702 glRasterPos2f (28 / m_fScale, -10 / m_fScale );
1703 GlobalOpenGL().drawChar(g_AxisName[nDim1]);
1704 glColor3fv (vector3_to_array(colourY));
1705 glRasterPos2f ( m_vOrigin[nDim1] - w + 25 / m_fScale, m_vOrigin[nDim2] + h - 30 / m_fScale );
1706 GlobalOpenGL().drawChar(g_AxisName[nDim2]);
1707 glRasterPos2f ( -10 / m_fScale, 28 / m_fScale );
1708 GlobalOpenGL().drawChar(g_AxisName[nDim2]);
1712 // show current work zone?
1713 // the work zone is used to place dropped points and brushes
1714 if (g_xywindow_globals_private.d_show_work)
1716 glColor3f( 1.0f, 0.0f, 0.0f );
1717 glBegin( GL_LINES );
1718 glVertex2f( xb, Select_getWorkZone().d_work_min[nDim2] );
1719 glVertex2f( xe, Select_getWorkZone().d_work_min[nDim2] );
1720 glVertex2f( xb, Select_getWorkZone().d_work_max[nDim2] );
1721 glVertex2f( xe, Select_getWorkZone().d_work_max[nDim2] );
1722 glVertex2f( Select_getWorkZone().d_work_min[nDim1], yb );
1723 glVertex2f( Select_getWorkZone().d_work_min[nDim1], ye );
1724 glVertex2f( Select_getWorkZone().d_work_max[nDim1], yb );
1725 glVertex2f( Select_getWorkZone().d_work_max[nDim1], ye );
1735 void XYWnd::XY_DrawBlockGrid()
1737 if(Map_FindWorldspawn(g_map) == 0)
1741 const char *value = Node_getEntity(*Map_GetWorldspawn(g_map))->getKeyValue("_blocksize" );
1743 sscanf( value, "%i", &g_xywindow_globals_private.blockSize );
1745 if (!g_xywindow_globals_private.blockSize || g_xywindow_globals_private.blockSize > 65536 || g_xywindow_globals_private.blockSize < 1024)
1746 // don't use custom blocksize if it is less than the default, or greater than the maximum world coordinate
1747 g_xywindow_globals_private.blockSize = 1024;
1749 float x, y, xb, xe, yb, ye;
1753 glDisable(GL_TEXTURE_2D);
1754 glDisable(GL_TEXTURE_1D);
1755 glDisable(GL_DEPTH_TEST);
1756 glDisable(GL_BLEND);
1758 w = (m_nWidth / 2 / m_fScale);
1759 h = (m_nHeight / 2 / m_fScale);
1761 int nDim1 = (m_viewType == YZ) ? 1 : 0;
1762 int nDim2 = (m_viewType == XY) ? 1 : 2;
1764 xb = m_vOrigin[nDim1] - w;
1765 if (xb < region_mins[nDim1])
1766 xb = region_mins[nDim1];
1767 xb = static_cast<float>(g_xywindow_globals_private.blockSize * floor (xb/g_xywindow_globals_private.blockSize));
1769 xe = m_vOrigin[nDim1] + w;
1770 if (xe > region_maxs[nDim1])
1771 xe = region_maxs[nDim1];
1772 xe = static_cast<float>(g_xywindow_globals_private.blockSize * ceil (xe/g_xywindow_globals_private.blockSize));
1774 yb = m_vOrigin[nDim2] - h;
1775 if (yb < region_mins[nDim2])
1776 yb = region_mins[nDim2];
1777 yb = static_cast<float>(g_xywindow_globals_private.blockSize * floor (yb/g_xywindow_globals_private.blockSize));
1779 ye = m_vOrigin[nDim2] + h;
1780 if (ye > region_maxs[nDim2])
1781 ye = region_maxs[nDim2];
1782 ye = static_cast<float>(g_xywindow_globals_private.blockSize * ceil (ye/g_xywindow_globals_private.blockSize));
1784 // draw major blocks
1786 glColor3fv(vector3_to_array(g_xywindow_globals.color_gridblock));
1791 for (x=xb ; x<=xe ; x+=g_xywindow_globals_private.blockSize)
1797 if (m_viewType == XY)
1799 for (y=yb ; y<=ye ; y+=g_xywindow_globals_private.blockSize)
1809 // draw coordinate text if needed
1811 if (m_viewType == XY && m_fScale > .1)
1813 for (x=xb ; x<xe ; x+=g_xywindow_globals_private.blockSize)
1814 for (y=yb ; y<ye ; y+=g_xywindow_globals_private.blockSize)
1816 glRasterPos2f (x+(g_xywindow_globals_private.blockSize/2), y+(g_xywindow_globals_private.blockSize/2));
1817 sprintf (text, "%i,%i",(int)floor(x/g_xywindow_globals_private.blockSize), (int)floor(y/g_xywindow_globals_private.blockSize) );
1818 GlobalOpenGL().drawString(text);
1822 glColor4f(0, 0, 0, 0);
1825 void XYWnd::DrawCameraIcon(const Vector3& origin, const Vector3& angles)
1827 float x, y, fov, box;
1830 fov = 48 / m_fScale;
1831 box = 16 / m_fScale;
1833 if (m_viewType == XY)
1837 a = degrees_to_radians(angles[CAMERA_YAW]);
1839 else if (m_viewType == YZ)
1843 a = degrees_to_radians(angles[CAMERA_PITCH]);
1849 a = degrees_to_radians(angles[CAMERA_PITCH]);
1852 glColor3f (0.0, 0.0, 1.0);
1853 glBegin(GL_LINE_STRIP);
1854 glVertex3f (x-box,y,0);
1855 glVertex3f (x,y+(box/2),0);
1856 glVertex3f (x+box,y,0);
1857 glVertex3f (x,y-(box/2),0);
1858 glVertex3f (x-box,y,0);
1859 glVertex3f (x+box,y,0);
1862 glBegin(GL_LINE_STRIP);
1863 glVertex3f (x + static_cast<float>(fov*cos(a+c_pi/4)), y + static_cast<float>(fov*sin(a+c_pi/4)), 0);
1864 glVertex3f (x, y, 0);
1865 glVertex3f (x + static_cast<float>(fov*cos(a-c_pi/4)), y + static_cast<float>(fov*sin(a-c_pi/4)), 0);
1871 float Betwixt(float f1, float f2)
1874 return f2 + ((f1 - f2) / 2);
1876 return f1 + ((f2 - f1) / 2);
1880 // can be greatly simplified but per usual i am in a hurry
1881 // which is not an excuse, just a fact
1882 void XYWnd::PaintSizeInfo(int nDim1, int nDim2, Vector3& vMinBounds, Vector3& vMaxBounds)
1884 if(vector3_equal(vMinBounds, vMaxBounds))
1888 const char* g_pDimStrings[] = {"x:", "y:", "z:"};
1889 typedef const char* OrgStrings[2];
1890 const OrgStrings g_pOrgStrings[] = { { "x:", "y:", }, { "x:", "z:", }, { "y:", "z:", } };
1892 Vector3 vSize(vector3_subtracted(vMaxBounds, vMinBounds));
1894 glColor3f(g_xywindow_globals.color_selbrushes[0] * .65f,
1895 g_xywindow_globals.color_selbrushes[1] * .65f,
1896 g_xywindow_globals.color_selbrushes[2] * .65f);
1898 StringOutputStream dimensions(16);
1900 if (m_viewType == XY)
1904 glVertex3f(vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f);
1905 glVertex3f(vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f);
1907 glVertex3f(vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f);
1908 glVertex3f(vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f);
1910 glVertex3f(vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f);
1911 glVertex3f(vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f);
1914 glVertex3f(vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2], 0.0f);
1915 glVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f);
1917 glVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f);
1918 glVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f);
1920 glVertex3f(vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2], 0.0f);
1921 glVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f);
1925 glRasterPos3f (Betwixt(vMinBounds[nDim1], vMaxBounds[nDim1]), vMinBounds[nDim2] - 20.0f / m_fScale, 0.0f);
1926 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
1927 GlobalOpenGL().drawString(dimensions.c_str());
1930 glRasterPos3f (vMaxBounds[nDim1] + 16.0f / m_fScale, Betwixt(vMinBounds[nDim2], vMaxBounds[nDim2]), 0.0f);
1931 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
1932 GlobalOpenGL().drawString(dimensions.c_str());
1935 glRasterPos3f (vMinBounds[nDim1] + 4, vMaxBounds[nDim2] + 8 / m_fScale, 0.0f);
1936 dimensions << "(" << g_pOrgStrings[0][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[0][1] << vMaxBounds[nDim2] << ")";
1937 GlobalOpenGL().drawString(dimensions.c_str());
1939 else if (m_viewType == XZ)
1943 glVertex3f(vMinBounds[nDim1], 0, vMinBounds[nDim2] - 6.0f / m_fScale);
1944 glVertex3f(vMinBounds[nDim1], 0, vMinBounds[nDim2] - 10.0f / m_fScale);
1946 glVertex3f(vMinBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale);
1947 glVertex3f(vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale);
1949 glVertex3f(vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 6.0f / m_fScale);
1950 glVertex3f(vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale);
1953 glVertex3f(vMaxBounds[nDim1] + 6.0f / m_fScale, 0,vMinBounds[nDim2]);
1954 glVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMinBounds[nDim2]);
1956 glVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMinBounds[nDim2]);
1957 glVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMaxBounds[nDim2]);
1959 glVertex3f(vMaxBounds[nDim1] + 6.0f / m_fScale, 0,vMaxBounds[nDim2]);
1960 glVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMaxBounds[nDim2]);
1964 glRasterPos3f (Betwixt(vMinBounds[nDim1], vMaxBounds[nDim1]), 0, vMinBounds[nDim2] - 20.0f / m_fScale);
1965 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
1966 GlobalOpenGL().drawString(dimensions.c_str());
1969 glRasterPos3f (vMaxBounds[nDim1] + 16.0f / m_fScale, 0, Betwixt(vMinBounds[nDim2], vMaxBounds[nDim2]));
1970 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
1971 GlobalOpenGL().drawString(dimensions.c_str());
1974 glRasterPos3f (vMinBounds[nDim1] + 4, 0, vMaxBounds[nDim2] + 8 / m_fScale);
1975 dimensions << "(" << g_pOrgStrings[1][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[1][1] << vMaxBounds[nDim2] << ")";
1976 GlobalOpenGL().drawString(dimensions.c_str());
1982 glVertex3f(0, vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale);
1983 glVertex3f(0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale);
1985 glVertex3f(0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale);
1986 glVertex3f(0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale);
1988 glVertex3f(0, vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale);
1989 glVertex3f(0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale);
1992 glVertex3f(0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2]);
1993 glVertex3f(0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2]);
1995 glVertex3f(0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2]);
1996 glVertex3f(0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2]);
1998 glVertex3f(0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2]);
1999 glVertex3f(0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2]);
2003 glRasterPos3f (0, Betwixt(vMinBounds[nDim1], vMaxBounds[nDim1]), vMinBounds[nDim2] - 20.0f / m_fScale);
2004 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
2005 GlobalOpenGL().drawString(dimensions.c_str());
2008 glRasterPos3f (0, vMaxBounds[nDim1] + 16.0f / m_fScale, Betwixt(vMinBounds[nDim2], vMaxBounds[nDim2]));
2009 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
2010 GlobalOpenGL().drawString(dimensions.c_str());
2013 glRasterPos3f (0, vMinBounds[nDim1] + 4.0f, vMaxBounds[nDim2] + 8 / m_fScale);
2014 dimensions << "(" << g_pOrgStrings[2][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[2][1] << vMaxBounds[nDim2] << ")";
2015 GlobalOpenGL().drawString(dimensions.c_str());
2019 class XYRenderer: public Renderer
2028 unsigned int m_highlight;
2032 XYRenderer(RenderStateFlags globalstate, Shader* selected) :
2033 m_globalstate(globalstate),
2034 m_state_selected(selected)
2036 ASSERT_NOTNULL(selected);
2037 m_state_stack.push_back(state_type());
2040 void SetState(Shader* state, EStyle style)
2042 ASSERT_NOTNULL(state);
2043 if(style == eWireframeOnly)
2044 m_state_stack.back().m_state = state;
2046 const EStyle getStyle() const
2048 return eWireframeOnly;
2052 m_state_stack.push_back(m_state_stack.back());
2056 ASSERT_MESSAGE(!m_state_stack.empty(), "popping empty stack");
2057 m_state_stack.pop_back();
2059 void Highlight(EHighlightMode mode, bool bEnable = true)
2062 ? m_state_stack.back().m_highlight |= mode
2063 : m_state_stack.back().m_highlight &= ~mode;
2065 void addRenderable(const OpenGLRenderable& renderable, const Matrix4& localToWorld)
2067 if(m_state_stack.back().m_highlight & ePrimitive)
2069 m_state_selected->addRenderable(renderable, localToWorld);
2073 m_state_stack.back().m_state->addRenderable(renderable, localToWorld);
2077 void render(const Matrix4& modelview, const Matrix4& projection)
2079 GlobalShaderCache().render(m_globalstate, modelview, projection);
2082 std::vector<state_type> m_state_stack;
2083 RenderStateFlags m_globalstate;
2084 Shader* m_state_selected;
2087 void XYWnd::updateProjection()
2089 m_projection[0] = 1.0f / static_cast<float>(m_nWidth / 2);
2090 m_projection[5] = 1.0f / static_cast<float>(m_nHeight / 2);
2091 m_projection[10] = 1.0f / (g_MaxWorldCoord * m_fScale);
2093 m_projection[12] = 0.0f;
2094 m_projection[13] = 0.0f;
2095 m_projection[14] = -1.0f;
2107 m_projection[11] = 0.0f;
2109 m_projection[15] = 1.0f;
2111 m_view.Construct(m_projection, m_modelview, m_nWidth, m_nHeight);
2114 // note: modelview matrix must have a uniform scale, otherwise strange things happen when rendering the rotation manipulator.
2115 void XYWnd::updateModelview()
2117 int nDim1 = (m_viewType == YZ) ? 1 : 0;
2118 int nDim2 = (m_viewType == XY) ? 1 : 2;
2121 m_modelview[12] = -m_vOrigin[nDim1] * m_fScale;
2122 m_modelview[13] = -m_vOrigin[nDim2] * m_fScale;
2123 m_modelview[14] = g_MaxWorldCoord * m_fScale;
2129 m_modelview[0] = m_fScale;
2134 m_modelview[5] = m_fScale;
2139 m_modelview[10] = -m_fScale;
2142 m_modelview[0] = m_fScale;
2148 m_modelview[6] = m_fScale;
2151 m_modelview[9] = m_fScale;
2152 m_modelview[10] = 0;
2157 m_modelview[2] = -m_fScale;
2159 m_modelview[4] = m_fScale;
2164 m_modelview[9] = m_fScale;
2165 m_modelview[10] = 0;
2169 m_modelview[3] = m_modelview[7] = m_modelview[11] = 0;
2170 m_modelview[15] = 1;
2172 m_view.Construct(m_projection, m_modelview, m_nWidth, m_nHeight);
2181 //#define DBG_SCENEDUMP
2183 void XYWnd::XY_Draw()
2188 glViewport(0, 0, m_nWidth, m_nHeight);
2189 glClearColor (g_xywindow_globals.color_gridback[0],
2190 g_xywindow_globals.color_gridback[1],
2191 g_xywindow_globals.color_gridback[2],0);
2193 glClear(GL_COLOR_BUFFER_BIT);
2199 glMatrixMode(GL_PROJECTION);
2200 glLoadMatrixf(reinterpret_cast<const float*>(&m_projection));
2202 glMatrixMode(GL_MODELVIEW);
2204 glScalef(m_fScale, m_fScale, 1);
2205 int nDim1 = (m_viewType == YZ) ? 1 : 0;
2206 int nDim2 = (m_viewType == XY) ? 1 : 2;
2207 glTranslatef(-m_vOrigin[nDim1], -m_vOrigin[nDim2], 0);
2209 glDisable (GL_LINE_STIPPLE);
2211 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
2212 glDisableClientState(GL_NORMAL_ARRAY);
2213 glDisableClientState(GL_COLOR_ARRAY);
2214 glDisable(GL_TEXTURE_2D);
2215 glDisable(GL_LIGHTING);
2216 glDisable(GL_COLOR_MATERIAL);
2217 glDisable(GL_DEPTH_TEST);
2220 if ( g_xywindow_globals_private.show_blocks)
2223 glLoadMatrixf(reinterpret_cast<const float*>(&m_modelview));
2225 unsigned int globalstate = RENDER_COLOURARRAY | RENDER_COLOURWRITE | RENDER_POLYGONSMOOTH | RENDER_LINESMOOTH;
2226 if(!g_xywindow_globals.m_bNoStipple)
2228 globalstate |= RENDER_LINESTIPPLE;
2232 XYRenderer renderer(globalstate, m_state_selected);
2234 Scene_Render(renderer, m_view);
2236 GlobalOpenGL_debugAssertNoErrors();
2237 renderer.render(m_modelview, m_projection);
2238 GlobalOpenGL_debugAssertNoErrors();
2241 glDepthMask(GL_FALSE);
2243 GlobalOpenGL_debugAssertNoErrors();
2245 glLoadMatrixf(reinterpret_cast<const float*>(&m_modelview));
2247 GlobalOpenGL_debugAssertNoErrors();
2248 glDisable(GL_LINE_STIPPLE);
2249 GlobalOpenGL_debugAssertNoErrors();
2251 GlobalOpenGL_debugAssertNoErrors();
2252 if(GlobalOpenGL().GL_1_3())
2254 glActiveTexture(GL_TEXTURE0);
2255 glClientActiveTexture(GL_TEXTURE0);
2257 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
2258 GlobalOpenGL_debugAssertNoErrors();
2259 glDisableClientState(GL_NORMAL_ARRAY);
2260 GlobalOpenGL_debugAssertNoErrors();
2261 glDisableClientState(GL_COLOR_ARRAY);
2262 GlobalOpenGL_debugAssertNoErrors();
2263 glDisable(GL_TEXTURE_2D);
2264 GlobalOpenGL_debugAssertNoErrors();
2265 glDisable(GL_LIGHTING);
2266 GlobalOpenGL_debugAssertNoErrors();
2267 glDisable(GL_COLOR_MATERIAL);
2268 GlobalOpenGL_debugAssertNoErrors();
2270 GlobalOpenGL_debugAssertNoErrors();
2274 if(g_xywindow_globals_private.m_bSizePaint && GlobalSelectionSystem().countSelected() != 0)
2277 Select_GetBounds(min, max);
2278 PaintSizeInfo(nDim1, nDim2, min, max);
2283 glColor4f(0.2f, 0.9f, 0.2f, 0.8f);
2285 if (m_viewType == XY)
2287 glVertex2f(2.0f * g_MinWorldCoord, m_mousePosition[1]);
2288 glVertex2f(2.0f * g_MaxWorldCoord, m_mousePosition[1]);
2289 glVertex2f(m_mousePosition[0], 2.0f * g_MinWorldCoord);
2290 glVertex2f(m_mousePosition[0], 2.0f * g_MaxWorldCoord);
2292 else if (m_viewType == YZ)
2294 glVertex3f(m_mousePosition[0], 2.0f * g_MinWorldCoord, m_mousePosition[2]);
2295 glVertex3f(m_mousePosition[0], 2.0f * g_MaxWorldCoord, m_mousePosition[2]);
2296 glVertex3f(m_mousePosition[0], m_mousePosition[1], 2.0f * g_MinWorldCoord);
2297 glVertex3f(m_mousePosition[0], m_mousePosition[1], 2.0f * g_MaxWorldCoord);
2301 glVertex3f (2.0f * g_MinWorldCoord, m_mousePosition[1], m_mousePosition[2]);
2302 glVertex3f (2.0f * g_MaxWorldCoord, m_mousePosition[1], m_mousePosition[2]);
2303 glVertex3f(m_mousePosition[0], m_mousePosition[1], 2.0f * g_MinWorldCoord);
2304 glVertex3f(m_mousePosition[0], m_mousePosition[1], 2.0f * g_MaxWorldCoord);
2311 GlobalClipPoints_Draw(m_fScale);
2314 GlobalOpenGL_debugAssertNoErrors();
2318 glScalef(m_fScale, m_fScale, 1);
2319 glTranslatef(-m_vOrigin[nDim1], -m_vOrigin[nDim2], 0);
2321 DrawCameraIcon (Camera_getOrigin(*g_pParentWnd->GetCamWnd()), Camera_getAngles(*g_pParentWnd->GetCamWnd()));
2323 Feedback_draw2D( m_viewType );
2325 if (g_xywindow_globals_private.show_outline)
2329 glMatrixMode (GL_PROJECTION);
2331 glOrtho (0, m_nWidth, 0, m_nHeight, 0, 1);
2333 glMatrixMode (GL_MODELVIEW);
2336 // four view mode doesn't colorize
2337 if (g_pParentWnd->CurrentStyle() == MainFrame::eSplit)
2338 glColor3fv(vector3_to_array(g_xywindow_globals.color_viewname));
2344 glColor3fv(vector3_to_array(g_xywindow_globals.AxisColorX));
2347 glColor3fv(vector3_to_array(g_xywindow_globals.AxisColorY));
2350 glColor3fv(vector3_to_array(g_xywindow_globals.AxisColorZ));
2354 glBegin (GL_LINE_LOOP);
2356 glVertex2i (m_nWidth-1, 0);
2357 glVertex2i (m_nWidth-1, m_nHeight-1);
2358 glVertex2i (0, m_nHeight-1);
2363 GlobalOpenGL_debugAssertNoErrors();
2368 void XYWnd_MouseToPoint(XYWnd* xywnd, int x, int y, Vector3& point)
2370 xywnd->XY_ToPoint(x, y, point);
2371 xywnd->XY_SnapToGrid(point);
2373 int nDim = (xywnd->GetViewType() == XY) ? 2 : (xywnd->GetViewType() == YZ) ? 0 : 1;
2374 float fWorkMid = float_mid(Select_getWorkZone().d_work_min[nDim], Select_getWorkZone().d_work_max[nDim]);
2375 point[nDim] = float_snapped(fWorkMid, GetGridSize());
2378 void XYWnd::OnEntityCreate (const char* item)
2380 StringOutputStream command;
2381 command << "entityCreate -class " << item;
2382 UndoableCommand undo(command.c_str());
2384 XYWnd_MouseToPoint(this, m_entityCreate_x, m_entityCreate_y, point);
2385 Entity_createFromSelection(item, point);
2390 void GetFocusPosition(Vector3& position)
2392 if(GlobalSelectionSystem().countSelected() != 0)
2394 Select_GetMid(position);
2398 position = Camera_getOrigin(*g_pParentWnd->GetCamWnd());
2402 void XYWnd_Focus(XYWnd* xywnd)
2405 GetFocusPosition(position);
2406 xywnd->PositionView(position);
2409 void XY_Split_Focus()
2412 GetFocusPosition(position);
2413 g_pParentWnd->GetXYWnd()->PositionView(position);
2414 g_pParentWnd->GetXZWnd()->PositionView(position);
2415 g_pParentWnd->GetYZWnd()->PositionView(position);
2420 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2426 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2427 xywnd->SetViewType(XY);
2433 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2434 xywnd->SetViewType(XZ);
2440 g_pParentWnd->GetXYWnd()->SetViewType(YZ);
2441 XYWnd_Focus(g_pParentWnd->GetXYWnd());
2446 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2447 if (xywnd->GetViewType() == XY)
2448 xywnd->SetViewType(XZ);
2449 else if (xywnd->GetViewType() == XZ)
2450 xywnd->SetViewType(YZ);
2452 xywnd->SetViewType(XY);
2458 if (g_pParentWnd->GetXYWnd())
2459 g_pParentWnd->GetXYWnd()->SetScale(1);
2460 if (g_pParentWnd->GetXZWnd())
2461 g_pParentWnd->GetXZWnd()->SetScale(1);
2462 if (g_pParentWnd->GetYZWnd())
2463 g_pParentWnd->GetYZWnd()->SetScale(1);
2468 XYWnd_ZoomIn(g_pParentWnd->ActiveXY());
2471 // NOTE: the zoom out factor is 4/5, we could think about customizing it
2472 // we don't go below a zoom factor corresponding to 10% of the max world size
2473 // (this has to be computed against the window size)
2476 XYWnd_ZoomOut(g_pParentWnd->ActiveXY());
2481 void ToggleShowCrosshair()
2484 XY_UpdateAllWindows();
2487 void ToggleShowSizeInfo()
2489 g_xywindow_globals_private.m_bSizePaint = !g_xywindow_globals_private.m_bSizePaint;
2490 XY_UpdateAllWindows();
2493 void ToggleShowGrid()
2495 g_xywindow_globals_private.d_showgrid = !g_xywindow_globals_private.d_showgrid;
2496 XY_UpdateAllWindows();
2499 ToggleShown g_xy_top_shown(true);
2501 void XY_Top_Shown_Construct(GtkWindow* parent)
2503 g_xy_top_shown.connect(GTK_WIDGET(parent));
2506 ToggleShown g_yz_side_shown(false);
2508 void YZ_Side_Shown_Construct(GtkWindow* parent)
2510 g_yz_side_shown.connect(GTK_WIDGET(parent));
2513 ToggleShown g_xz_front_shown(false);
2515 void XZ_Front_Shown_Construct(GtkWindow* parent)
2517 g_xz_front_shown.connect(GTK_WIDGET(parent));
2521 class EntityClassMenu : public ModuleObserver
2523 std::size_t m_unrealised;
2525 EntityClassMenu() : m_unrealised(1)
2530 if(--m_unrealised == 0)
2536 if(++m_unrealised == 1)
2538 if(XYWnd::m_mnuDrop != 0)
2540 gtk_widget_destroy(GTK_WIDGET(XYWnd::m_mnuDrop));
2541 XYWnd::m_mnuDrop = 0;
2547 EntityClassMenu g_EntityClassMenu;
2552 void ShowNamesToggle()
2554 GlobalEntityCreator().setShowNames(!GlobalEntityCreator().getShowNames());
2555 XY_UpdateAllWindows();
2557 typedef FreeCaller<ShowNamesToggle> ShowNamesToggleCaller;
2558 void ShowNamesExport(const BoolImportCallback& importer)
2560 importer(GlobalEntityCreator().getShowNames());
2562 typedef FreeCaller1<const BoolImportCallback&, ShowNamesExport> ShowNamesExportCaller;
2564 void ShowAnglesToggle()
2566 GlobalEntityCreator().setShowAngles(!GlobalEntityCreator().getShowAngles());
2567 XY_UpdateAllWindows();
2569 typedef FreeCaller<ShowAnglesToggle> ShowAnglesToggleCaller;
2570 void ShowAnglesExport(const BoolImportCallback& importer)
2572 importer(GlobalEntityCreator().getShowAngles());
2574 typedef FreeCaller1<const BoolImportCallback&, ShowAnglesExport> ShowAnglesExportCaller;
2576 void ShowBlocksToggle()
2578 g_xywindow_globals_private.show_blocks ^= 1;
2579 XY_UpdateAllWindows();
2581 typedef FreeCaller<ShowBlocksToggle> ShowBlocksToggleCaller;
2582 void ShowBlocksExport(const BoolImportCallback& importer)
2584 importer(g_xywindow_globals_private.show_blocks);
2586 typedef FreeCaller1<const BoolImportCallback&, ShowBlocksExport> ShowBlocksExportCaller;
2588 void ShowCoordinatesToggle()
2590 g_xywindow_globals_private.show_coordinates ^= 1;
2591 XY_UpdateAllWindows();
2593 typedef FreeCaller<ShowCoordinatesToggle> ShowCoordinatesToggleCaller;
2594 void ShowCoordinatesExport(const BoolImportCallback& importer)
2596 importer(g_xywindow_globals_private.show_coordinates);
2598 typedef FreeCaller1<const BoolImportCallback&, ShowCoordinatesExport> ShowCoordinatesExportCaller;
2600 void ShowOutlineToggle()
2602 g_xywindow_globals_private.show_outline ^= 1;
2603 XY_UpdateAllWindows();
2605 typedef FreeCaller<ShowOutlineToggle> ShowOutlineToggleCaller;
2606 void ShowOutlineExport(const BoolImportCallback& importer)
2608 importer(g_xywindow_globals_private.show_outline);
2610 typedef FreeCaller1<const BoolImportCallback&, ShowOutlineExport> ShowOutlineExportCaller;
2612 void ShowAxesToggle()
2614 g_xywindow_globals_private.show_axis ^= 1;
2615 XY_UpdateAllWindows();
2617 typedef FreeCaller<ShowAxesToggle> ShowAxesToggleCaller;
2618 void ShowAxesExport(const BoolImportCallback& importer)
2620 importer(g_xywindow_globals_private.show_axis);
2622 typedef FreeCaller1<const BoolImportCallback&, ShowAxesExport> ShowAxesExportCaller;
2624 void ShowWorkzoneToggle()
2626 g_xywindow_globals_private.d_show_work ^= 1;
2627 XY_UpdateAllWindows();
2629 typedef FreeCaller<ShowWorkzoneToggle> ShowWorkzoneToggleCaller;
2630 void ShowWorkzoneExport(const BoolImportCallback& importer)
2632 importer(g_xywindow_globals_private.d_show_work);
2634 typedef FreeCaller1<const BoolImportCallback&, ShowWorkzoneExport> ShowWorkzoneExportCaller;
2636 ShowNamesExportCaller g_show_names_caller;
2637 BoolExportCallback g_show_names_callback(g_show_names_caller);
2638 ToggleItem g_show_names(g_show_names_callback);
2640 ShowAnglesExportCaller g_show_angles_caller;
2641 BoolExportCallback g_show_angles_callback(g_show_angles_caller);
2642 ToggleItem g_show_angles(g_show_angles_callback);
2644 ShowBlocksExportCaller g_show_blocks_caller;
2645 BoolExportCallback g_show_blocks_callback(g_show_blocks_caller);
2646 ToggleItem g_show_blocks(g_show_blocks_callback);
2648 ShowCoordinatesExportCaller g_show_coordinates_caller;
2649 BoolExportCallback g_show_coordinates_callback(g_show_coordinates_caller);
2650 ToggleItem g_show_coordinates(g_show_coordinates_callback);
2652 ShowOutlineExportCaller g_show_outline_caller;
2653 BoolExportCallback g_show_outline_callback(g_show_outline_caller);
2654 ToggleItem g_show_outline(g_show_outline_callback);
2656 ShowAxesExportCaller g_show_axes_caller;
2657 BoolExportCallback g_show_axes_callback(g_show_axes_caller);
2658 ToggleItem g_show_axes(g_show_axes_callback);
2660 ShowWorkzoneExportCaller g_show_workzone_caller;
2661 BoolExportCallback g_show_workzone_callback(g_show_workzone_caller);
2662 ToggleItem g_show_workzone(g_show_workzone_callback);
2664 void XYShow_registerCommands()
2666 GlobalToggles_insert("ShowAngles", ShowAnglesToggleCaller(), ToggleItem::AddCallbackCaller(g_show_angles));
2667 GlobalToggles_insert("ShowNames", ShowNamesToggleCaller(), ToggleItem::AddCallbackCaller(g_show_names));
2668 GlobalToggles_insert("ShowBlocks", ShowBlocksToggleCaller(), ToggleItem::AddCallbackCaller(g_show_blocks));
2669 GlobalToggles_insert("ShowCoordinates", ShowCoordinatesToggleCaller(), ToggleItem::AddCallbackCaller(g_show_coordinates));
2670 GlobalToggles_insert("ShowWindowOutline", ShowOutlineToggleCaller(), ToggleItem::AddCallbackCaller(g_show_outline));
2671 GlobalToggles_insert("ShowAxes", ShowAxesToggleCaller(), ToggleItem::AddCallbackCaller(g_show_axes));
2672 GlobalToggles_insert("ShowWorkzone", ShowWorkzoneToggleCaller(), ToggleItem::AddCallbackCaller(g_show_workzone));
2675 void XYWnd_registerShortcuts()
2677 command_connect_accelerator("ToggleCrosshairs");
2678 command_connect_accelerator("ToggleSizePaint");
2683 void Orthographic_constructPreferences(PreferencesPage& page)
2685 page.appendCheckBox("", "Solid selection boxes", g_xywindow_globals.m_bNoStipple);
2686 page.appendCheckBox("", "Display size info", g_xywindow_globals_private.m_bSizePaint);
2687 page.appendCheckBox("", "Chase mouse during drags", g_xywindow_globals_private.m_bChaseMouse);
2688 page.appendCheckBox("", "Update views on camera move", g_xywindow_globals_private.m_bCamXYUpdate);
2690 void Orthographic_constructPage(PreferenceGroup& group)
2692 PreferencesPage page(group.createPage("Orthographic", "Orthographic View Preferences"));
2693 Orthographic_constructPreferences(page);
2695 void Orthographic_registerPreferencesPage()
2697 PreferencesDialog_addSettingsPage(FreeCaller1<PreferenceGroup&, Orthographic_constructPage>());
2700 void Clipper_constructPreferences(PreferencesPage& page)
2702 page.appendCheckBox("", "Clipper tool uses caulk", g_clip_useCaulk);
2704 void Clipper_constructPage(PreferenceGroup& group)
2706 PreferencesPage page(group.createPage("Clipper", "Clipper Tool Settings"));
2707 Clipper_constructPreferences(page);
2709 void Clipper_registerPreferencesPage()
2711 PreferencesDialog_addSettingsPage(FreeCaller1<PreferenceGroup&, Clipper_constructPage>());
2715 #include "preferencesystem.h"
2716 #include "stringio.h"
2721 void ToggleShown_importBool(ToggleShown& self, bool value)
2725 typedef ReferenceCaller1<ToggleShown, bool, ToggleShown_importBool> ToggleShownImportBoolCaller;
2726 void ToggleShown_exportBool(const ToggleShown& self, const BoolImportCallback& importer)
2728 importer(self.active());
2730 typedef ConstReferenceCaller1<ToggleShown, const BoolImportCallback&, ToggleShown_exportBool> ToggleShownExportBoolCaller;
2733 void XYWindow_Construct()
2735 GlobalCommands_insert("ToggleCrosshairs", FreeCaller<ToggleShowCrosshair>(), Accelerator('X', (GdkModifierType)GDK_SHIFT_MASK));
2736 GlobalCommands_insert("ToggleSizePaint", FreeCaller<ToggleShowSizeInfo>(), Accelerator('J'));
2737 GlobalCommands_insert("ToggleGrid", FreeCaller<ToggleShowGrid>(), Accelerator('0'));
2739 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)));
2740 GlobalToggles_insert("ToggleSideView", ToggleShown::ToggleCaller(g_yz_side_shown), ToggleItem::AddCallbackCaller(g_yz_side_shown.m_item));
2741 GlobalToggles_insert("ToggleFrontView", ToggleShown::ToggleCaller(g_xz_front_shown), ToggleItem::AddCallbackCaller(g_xz_front_shown.m_item));
2742 GlobalCommands_insert("NextView", FreeCaller<XY_Next>(), Accelerator(GDK_Tab, (GdkModifierType)GDK_CONTROL_MASK));
2743 GlobalCommands_insert("ZoomIn", FreeCaller<XY_ZoomIn>(), Accelerator(GDK_Delete));
2744 GlobalCommands_insert("ZoomOut", FreeCaller<XY_ZoomOut>(), Accelerator(GDK_Insert));
2745 GlobalCommands_insert("ViewTop", FreeCaller<XY_Top>());
2746 GlobalCommands_insert("ViewSide", FreeCaller<XY_Side>());
2747 GlobalCommands_insert("ViewFront", FreeCaller<XY_Front>());
2748 GlobalCommands_insert("Zoom100", FreeCaller<XY_Zoom100>());
2749 GlobalCommands_insert("CenterXYViews", FreeCaller<XY_Split_Focus>(), Accelerator(GDK_Tab, (GdkModifierType)(GDK_SHIFT_MASK|GDK_CONTROL_MASK)));
2750 GlobalCommands_insert("CenterXYView", FreeCaller<XY_Focus>(), Accelerator(GDK_Tab, (GdkModifierType)(GDK_SHIFT_MASK|GDK_CONTROL_MASK)));
2752 GlobalPreferenceSystem().registerPreference("ClipCaulk", BoolImportStringCaller(g_clip_useCaulk), BoolExportStringCaller(g_clip_useCaulk));
2754 GlobalPreferenceSystem().registerPreference("NewRightClick", BoolImportStringCaller(g_xywindow_globals.m_bRightClick), BoolExportStringCaller(g_xywindow_globals.m_bRightClick));
2755 GlobalPreferenceSystem().registerPreference("ChaseMouse", BoolImportStringCaller(g_xywindow_globals_private.m_bChaseMouse), BoolExportStringCaller(g_xywindow_globals_private.m_bChaseMouse));
2756 GlobalPreferenceSystem().registerPreference("SizePainting", BoolImportStringCaller(g_xywindow_globals_private.m_bSizePaint), BoolExportStringCaller(g_xywindow_globals_private.m_bSizePaint));
2757 GlobalPreferenceSystem().registerPreference("NoStipple", BoolImportStringCaller(g_xywindow_globals.m_bNoStipple), BoolExportStringCaller(g_xywindow_globals.m_bNoStipple));
2758 GlobalPreferenceSystem().registerPreference("SI_ShowCoords", BoolImportStringCaller(g_xywindow_globals_private.show_coordinates), BoolExportStringCaller(g_xywindow_globals_private.show_coordinates));
2759 GlobalPreferenceSystem().registerPreference("SI_ShowOutlines", BoolImportStringCaller(g_xywindow_globals_private.show_outline), BoolExportStringCaller(g_xywindow_globals_private.show_outline));
2760 GlobalPreferenceSystem().registerPreference("SI_ShowAxis", BoolImportStringCaller(g_xywindow_globals_private.show_axis), BoolExportStringCaller(g_xywindow_globals_private.show_axis));
2761 GlobalPreferenceSystem().registerPreference("CamXYUpdate", BoolImportStringCaller(g_xywindow_globals_private.m_bCamXYUpdate), BoolExportStringCaller(g_xywindow_globals_private.m_bCamXYUpdate));
2763 GlobalPreferenceSystem().registerPreference("SI_AxisColors0", Vector3ImportStringCaller(g_xywindow_globals.AxisColorX), Vector3ExportStringCaller(g_xywindow_globals.AxisColorX));
2764 GlobalPreferenceSystem().registerPreference("SI_AxisColors1", Vector3ImportStringCaller(g_xywindow_globals.AxisColorY), Vector3ExportStringCaller(g_xywindow_globals.AxisColorY));
2765 GlobalPreferenceSystem().registerPreference("SI_AxisColors2", Vector3ImportStringCaller(g_xywindow_globals.AxisColorZ), Vector3ExportStringCaller(g_xywindow_globals.AxisColorZ));
2766 GlobalPreferenceSystem().registerPreference("SI_Colors1", Vector3ImportStringCaller(g_xywindow_globals.color_gridback), Vector3ExportStringCaller(g_xywindow_globals.color_gridback));
2767 GlobalPreferenceSystem().registerPreference("SI_Colors2", Vector3ImportStringCaller(g_xywindow_globals.color_gridminor), Vector3ExportStringCaller(g_xywindow_globals.color_gridminor));
2768 GlobalPreferenceSystem().registerPreference("SI_Colors3", Vector3ImportStringCaller(g_xywindow_globals.color_gridmajor), Vector3ExportStringCaller(g_xywindow_globals.color_gridmajor));
2769 GlobalPreferenceSystem().registerPreference("SI_Colors6", Vector3ImportStringCaller(g_xywindow_globals.color_gridblock), Vector3ExportStringCaller(g_xywindow_globals.color_gridblock));
2770 GlobalPreferenceSystem().registerPreference("SI_Colors7", Vector3ImportStringCaller(g_xywindow_globals.color_gridtext), Vector3ExportStringCaller(g_xywindow_globals.color_gridtext));
2771 GlobalPreferenceSystem().registerPreference("SI_Colors8", Vector3ImportStringCaller(g_xywindow_globals.color_brushes), Vector3ExportStringCaller(g_xywindow_globals.color_brushes));
2772 GlobalPreferenceSystem().registerPreference("SI_Colors9", Vector3ImportStringCaller(g_xywindow_globals.color_selbrushes), Vector3ExportStringCaller(g_xywindow_globals.color_selbrushes));
2773 GlobalPreferenceSystem().registerPreference("SI_Colors10", Vector3ImportStringCaller(g_xywindow_globals.color_clipper), Vector3ExportStringCaller(g_xywindow_globals.color_clipper));
2774 GlobalPreferenceSystem().registerPreference("SI_Colors11", Vector3ImportStringCaller(g_xywindow_globals.color_viewname), Vector3ExportStringCaller(g_xywindow_globals.color_viewname));
2775 GlobalPreferenceSystem().registerPreference("SI_Colors13", Vector3ImportStringCaller(g_xywindow_globals.color_gridminor_alt), Vector3ExportStringCaller(g_xywindow_globals.color_gridminor_alt));
2776 GlobalPreferenceSystem().registerPreference("SI_Colors14", Vector3ImportStringCaller(g_xywindow_globals.color_gridmajor_alt), Vector3ExportStringCaller(g_xywindow_globals.color_gridmajor_alt));
2779 GlobalPreferenceSystem().registerPreference("XZVIS", makeBoolStringImportCallback(ToggleShownImportBoolCaller(g_xz_front_shown)), makeBoolStringExportCallback(ToggleShownExportBoolCaller(g_xz_front_shown)));
2780 GlobalPreferenceSystem().registerPreference("YZVIS", makeBoolStringImportCallback(ToggleShownImportBoolCaller(g_yz_side_shown)), makeBoolStringExportCallback(ToggleShownExportBoolCaller(g_yz_side_shown)));
2782 Orthographic_registerPreferencesPage();
2783 Clipper_registerPreferencesPage();
2785 XYWnd::captureStates();
2786 GlobalEntityClassManager().attach(g_EntityClassMenu);
2789 void XYWindow_Destroy()
2791 GlobalEntityClassManager().detach(g_EntityClassMenu);
2792 XYWnd::releaseStates();