2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 // Leonardo Zide (leo@lokigames.com)
30 #include "debugging/debugging.h"
37 #include "ifilesystem.h"
40 #include "gtkutil/messagebox.h"
42 #include <gtk/gtklabel.h>
43 #include <gtk/gtkmenuitem.h>
45 #include "generic/callback.h"
46 #include "string/string.h"
47 #include "stream/stringstream.h"
50 #include "eclasslib.h"
52 #include "moduleobserver.h"
54 #include "gtkutil/menu.h"
55 #include "gtkutil/container.h"
56 #include "gtkutil/widget.h"
57 #include "gtkutil/glwidget.h"
58 #include "gtkutil/filechooser.h"
62 #include "brushmanip.h"
63 #include "selection.h"
65 #include "camwindow.h"
66 #include "texwindow.h"
67 #include "mainframe.h"
68 #include "preferences.h"
72 #include "windowobservers.h"
74 void LoadTextureRGBA(qtexture_t* q, unsigned char* pPixels, int nWidth, int nHeight);
77 extern bool g_brush_always_caulk;
83 Vector3 m_ptClip; // the 3d point
92 m_ptClip[0] = m_ptClip[1] = m_ptClip[2] = 0.0;
108 /*! Draw clip/path point with rasterized number label */
109 void Draw(int num, float scale);
110 /*! Draw clip/path point with rasterized string label */
111 void Draw(const char *label, float scale);
114 VIEWTYPE g_clip_viewtype;
115 bool g_bSwitch = true;
116 bool g_clip_useCaulk = false;
120 ClipPoint* g_pMovingClip = 0;
122 /* Drawing clip points */
123 void ClipPoint::Draw(int num, float scale)
125 StringOutputStream label(4);
127 Draw(label.c_str(), scale);
130 void ClipPoint::Draw(const char *label, float scale)
134 glColor3fv(vector3_to_array(g_xywindow_globals.color_clipper));
136 glVertex3fv(vector3_to_array(m_ptClip));
140 float offset = 2.0f / scale;
143 glRasterPos3f (m_ptClip[0] + offset, m_ptClip[1] + offset, m_ptClip[2] + offset);
144 glCallLists (GLsizei(strlen(label)), GL_UNSIGNED_BYTE, label);
147 float fDiff(float f1, float f2)
155 inline double ClipPoint_Intersect(const ClipPoint& clip, const Vector3& point, VIEWTYPE viewtype, float scale)
157 int nDim1 = (viewtype == YZ) ? 1 : 0;
158 int nDim2 = (viewtype == XY) ? 1 : 2;
159 double screenDistanceSquared(vector2_length_squared(Vector2(fDiff(clip.m_ptClip[nDim1], point[nDim1]) * scale, fDiff(clip.m_ptClip[nDim2], point[nDim2]) * scale)));
160 if(screenDistanceSquared < 8*8)
162 return screenDistanceSquared;
167 inline void ClipPoint_testSelect(ClipPoint& clip, const Vector3& point, VIEWTYPE viewtype, float scale, double& bestDistance, ClipPoint*& bestClip)
171 double distance = ClipPoint_Intersect(clip, point, viewtype, scale);
172 if(distance < bestDistance)
174 bestDistance = distance;
180 inline ClipPoint* GlobalClipPoints_Find(const Vector3& point, VIEWTYPE viewtype, float scale)
182 double bestDistance = FLT_MAX;
183 ClipPoint* bestClip = 0;
184 ClipPoint_testSelect(g_Clip1, point, viewtype, scale, bestDistance, bestClip);
185 ClipPoint_testSelect(g_Clip2, point, viewtype, scale, bestDistance, bestClip);
186 ClipPoint_testSelect(g_Clip3, point, viewtype, scale, bestDistance, bestClip);
190 inline void GlobalClipPoints_Draw(float scale)
194 g_Clip1.Draw(1, scale);
196 g_Clip2.Draw(2, scale);
198 g_Clip3.Draw(3, scale);
201 inline bool GlobalClipPoints_valid()
203 return g_Clip1.Set() && g_Clip2.Set();
206 void PlanePointsFromClipPoints(Vector3 planepts[3], const AABB& bounds, int viewtype)
208 ASSERT_MESSAGE(GlobalClipPoints_valid(), "clipper points not initialised");
209 planepts[0] = g_Clip1.m_ptClip;
210 planepts[1] = g_Clip2.m_ptClip;
211 planepts[2] = g_Clip3.m_ptClip;
212 Vector3 maxs(vector3_added(bounds.origin, bounds.extents));
213 Vector3 mins(vector3_subtracted(bounds.origin, bounds.extents));
216 int n = (viewtype == XY) ? 2 : (viewtype == YZ) ? 0 : 1;
217 int x = (n == 0) ? 1 : 0;
218 int y = (n == 2) ? 1 : 2;
220 if (n == 1) // on viewtype XZ, flip clip points
222 planepts[0][n] = maxs[n];
223 planepts[1][n] = maxs[n];
224 planepts[2][x] = g_Clip1.m_ptClip[x];
225 planepts[2][y] = g_Clip1.m_ptClip[y];
226 planepts[2][n] = mins[n];
230 planepts[0][n] = mins[n];
231 planepts[1][n] = mins[n];
232 planepts[2][x] = g_Clip1.m_ptClip[x];
233 planepts[2][y] = g_Clip1.m_ptClip[y];
234 planepts[2][n] = maxs[n];
242 if(!GlobalClipPoints_valid())
244 planepts[0] = Vector3(0, 0, 0);
245 planepts[1] = Vector3(0, 0, 0);
246 planepts[2] = Vector3(0, 0, 0);
247 Scene_BrushSetClipPlane(GlobalSceneGraph(), Plane3(0, 0, 0, 0));
251 AABB bounds(Vector3(0, 0, 0), Vector3(64, 64, 64));
252 PlanePointsFromClipPoints(planepts, bounds, g_clip_viewtype);
255 std::swap(planepts[0], planepts[1]);
257 Scene_BrushSetClipPlane(GlobalSceneGraph(), plane3_for_points(planepts[0], planepts[1], planepts[2]));
259 ClipperChangeNotify();
262 const char* Clip_getShader()
264 return g_clip_useCaulk ? "textures/common/caulk" : TextureBrowser_GetSelectedShader(GlobalTextureBrowser());
269 if (ClipMode() && GlobalClipPoints_valid())
272 AABB bounds(Vector3(0, 0, 0), Vector3(64, 64, 64));
273 PlanePointsFromClipPoints(planepts, bounds, g_clip_viewtype);
274 Scene_BrushSplitByPlane(GlobalSceneGraph(), planepts[0], planepts[1], planepts[2], Clip_getShader(), (!g_bSwitch) ? eFront : eBack);
279 ClipperChangeNotify();
285 if (ClipMode() && GlobalClipPoints_valid())
288 AABB bounds(Vector3(0, 0, 0), Vector3(64, 64, 64));
289 PlanePointsFromClipPoints(planepts, bounds, g_clip_viewtype);
290 Scene_BrushSplitByPlane(GlobalSceneGraph(), planepts[0], planepts[1], planepts[2], Clip_getShader(), eFrontAndBack);
295 ClipperChangeNotify();
301 g_bSwitch = !g_bSwitch;
303 ClipperChangeNotify();
306 void OnClipMode(bool enabled)
312 if(!enabled && g_pMovingClip)
318 ClipperChangeNotify();
323 return GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eClip;
326 void NewClipPoint(const Vector3& point)
328 if (g_Clip1.Set() == false)
330 g_Clip1.m_ptClip = point;
333 else if (g_Clip2.Set() == false)
335 g_Clip2.m_ptClip = point;
338 else if (g_Clip3.Set() == false)
340 g_Clip3.m_ptClip = point;
348 g_Clip1.m_ptClip = point;
353 ClipperChangeNotify();
358 struct xywindow_globals_private_t
362 // these are in the View > Show menu with Show coordinates
364 bool show_coordinates;
378 xywindow_globals_private_t() :
382 show_coordinates(true),
391 m_bCamXYUpdate(true),
399 xywindow_globals_t g_xywindow_globals;
400 xywindow_globals_private_t g_xywindow_globals_private;
402 const unsigned int RAD_NONE = 0x00;
403 const unsigned int RAD_SHIFT = 0x01;
404 const unsigned int RAD_ALT = 0x02;
405 const unsigned int RAD_CONTROL = 0x04;
406 const unsigned int RAD_PRESS = 0x08;
407 const unsigned int RAD_LBUTTON = 0x10;
408 const unsigned int RAD_MBUTTON = 0x20;
409 const unsigned int RAD_RBUTTON = 0x40;
411 inline ButtonIdentifier button_for_flags(unsigned int flags)
413 if(flags & RAD_LBUTTON)
415 if(flags & RAD_RBUTTON)
416 return c_buttonRight;
417 if(flags & RAD_MBUTTON)
418 return c_buttonMiddle;
419 return c_buttonInvalid;
422 inline ModifierFlags modifiers_for_flags(unsigned int flags)
424 ModifierFlags modifiers = c_modifierNone;
425 if(flags & RAD_SHIFT)
426 modifiers |= c_modifierShift;
427 if(flags & RAD_CONTROL)
428 modifiers |= c_modifierControl;
430 modifiers |= c_modifierAlt;
434 inline unsigned int buttons_for_button_and_modifiers(ButtonIdentifier button, ModifierFlags flags)
436 unsigned int buttons = 0;
438 switch (button.get())
440 case ButtonEnumeration::LEFT: buttons |= RAD_LBUTTON; break;
441 case ButtonEnumeration::MIDDLE: buttons |= RAD_MBUTTON; break;
442 case ButtonEnumeration::RIGHT: buttons |= RAD_RBUTTON; break;
445 if(bitfield_enabled(flags, c_modifierControl))
446 buttons |= RAD_CONTROL;
448 if(bitfield_enabled(flags, c_modifierShift))
449 buttons |= RAD_SHIFT;
451 if(bitfield_enabled(flags, c_modifierAlt))
457 inline unsigned int buttons_for_event_button(GdkEventButton* event)
459 unsigned int flags = 0;
461 switch (event->button)
463 case 1: flags |= RAD_LBUTTON; break;
464 case 2: flags |= RAD_MBUTTON; break;
465 case 3: flags |= RAD_RBUTTON; break;
468 if ((event->state & GDK_CONTROL_MASK) != 0)
469 flags |= RAD_CONTROL;
471 if ((event->state & GDK_SHIFT_MASK) != 0)
474 if((event->state & GDK_MOD1_MASK) != 0)
480 inline unsigned int buttons_for_state(guint state)
482 unsigned int flags = 0;
484 if ((state & GDK_BUTTON1_MASK) != 0)
485 flags |= RAD_LBUTTON;
487 if ((state & GDK_BUTTON2_MASK) != 0)
488 flags |= RAD_MBUTTON;
490 if ((state & GDK_BUTTON3_MASK) != 0)
491 flags |= RAD_RBUTTON;
493 if ((state & GDK_CONTROL_MASK) != 0)
494 flags |= RAD_CONTROL;
496 if ((state & GDK_SHIFT_MASK) != 0)
499 if ((state & GDK_MOD1_MASK) != 0)
506 void XYWnd::SetScale(float f)
514 void XYWnd_ZoomIn(XYWnd* xy)
516 float max_scale = 64;
517 float scale = xy->Scale() * 5.0f / 4.0f;
518 if(scale > max_scale)
520 if(xy->Scale() != max_scale)
522 xy->SetScale (max_scale);
532 // NOTE: the zoom out factor is 4/5, we could think about customizing it
533 // we don't go below a zoom factor corresponding to 10% of the max world size
534 // (this has to be computed against the window size)
535 void XYWnd_ZoomOut(XYWnd* xy)
537 float min_scale = MIN(xy->Width(),xy->Height()) / ( 1.1f * (g_MaxWorldCoord-g_MinWorldCoord));
538 float scale = xy->Scale() * 4.0f / 5.0f;
539 if(scale < min_scale)
541 if(xy->Scale() != min_scale)
543 xy->SetScale (min_scale);
552 VIEWTYPE GlobalXYWnd_getCurrentViewType()
554 ASSERT_NOTNULL(g_pParentWnd);
555 ASSERT_NOTNULL(g_pParentWnd->ActiveXY());
556 return g_pParentWnd->ActiveXY()->GetViewType();
559 // =============================================================================
562 bool g_bCrossHairs = false;
564 GtkMenu* XYWnd::m_mnuDrop = 0;
566 // this is disabled, and broken
567 // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=394
572 width = g_pParentWnd->ActiveXY()->Width();
573 height = g_pParentWnd->ActiveXY()->Height();
575 const char* filename;
577 filename = file_dialog(GTK_WIDGET(MainFrame_getWindow()), FALSE, "Save Image", 0, FILTER_BMP);
581 g_pParentWnd->ActiveXY()->MakeCurrent();
582 img = (unsigned char*)malloc (width*height*3);
583 glReadPixels (0,0,width,height,GL_RGB,GL_UNSIGNED_BYTE,img);
586 fp = fopen(filename, "wb");
590 unsigned long cmap, bfSize;
594 bfSize = 54 + width*height*3;
596 long byteswritten = 0;
597 long pixoff = 54 + cmap*4;
599 char m1 ='B', m2 ='M';
600 fwrite(&m1, 1, 1, fp); byteswritten++; // B
601 fwrite(&m2, 1, 1, fp); byteswritten++; // M
602 fwrite(&bfSize, 4, 1, fp); byteswritten+=4;// bfSize
603 fwrite(&res, 2, 1, fp); byteswritten+=2;// bfReserved1
604 fwrite(&res, 2, 1, fp); byteswritten+=2;// bfReserved2
605 fwrite(&pixoff, 4, 1, fp); byteswritten+=4;// bfOffBits
607 unsigned long biSize = 40, compress = 0, size = 0;
609 unsigned short planes = 1;
610 fwrite(&biSize, 4, 1, fp); byteswritten+=4;// biSize
611 fwrite(&width, 4, 1, fp); byteswritten+=4;// biWidth
612 fwrite(&height, 4, 1, fp); byteswritten+=4;// biHeight
613 fwrite(&planes, 2, 1, fp); byteswritten+=2;// biPlanes
614 fwrite(&bits, 2, 1, fp); byteswritten+=2;// biBitCount
615 fwrite(&compress, 4, 1, fp);byteswritten+=4;// biCompression
616 fwrite(&size, 4, 1, fp); byteswritten+=4;// biSizeImage
617 fwrite(&pixels, 4, 1, fp); byteswritten+=4;// biXPelsPerMeter
618 fwrite(&pixels, 4, 1, fp); byteswritten+=4;// biYPelsPerMeter
619 fwrite(&cmap, 4, 1, fp); byteswritten+=4;// biClrUsed
620 fwrite(&cmap, 4, 1, fp); byteswritten+=4;// biClrImportant
622 unsigned long widthDW = (((width*24) + 31) / 32 * 4);
623 long row, row_size = width*3;
624 for (row = 0; row < height; row++)
626 unsigned char* buf = img+row*row_size;
630 for (col = 0; col < row_size; col += 3)
632 putc(buf[col+2], fp);
633 putc(buf[col+1], fp);
636 byteswritten += row_size;
639 for (count = row_size; count < widthDW; count++)
641 putc(0, fp); // dummy
656 Timer g_chasemouse_timer;
658 void XYWnd::ChaseMouse()
660 float multiplier = g_chasemouse_timer.elapsed_msec() / 10.0f;
661 Scroll(float_to_integer(multiplier * m_chasemouse_delta_x), float_to_integer(multiplier * -m_chasemouse_delta_y));
663 //globalOutputStream() << "chasemouse: multiplier=" << multiplier << " x=" << m_chasemouse_delta_x << " y=" << m_chasemouse_delta_y << '\n';
665 XY_MouseMoved(m_chasemouse_current_x, m_chasemouse_current_y , getButtonState());
666 g_chasemouse_timer.start();
669 gboolean xywnd_chasemouse(gpointer data)
671 reinterpret_cast<XYWnd*>(data)->ChaseMouse();
675 inline const int& min_int(const int& left, const int& right)
677 return std::min(left, right);
680 bool XYWnd::chaseMouseMotion(int pointx, int pointy)
682 m_chasemouse_delta_x = 0;
683 m_chasemouse_delta_y = 0;
685 if (g_xywindow_globals_private.m_bChaseMouse && getButtonState() == RAD_LBUTTON)
687 const int epsilon = 16;
689 if (pointx < epsilon)
691 m_chasemouse_delta_x = std::max(pointx, 0) - epsilon;
693 else if ((pointx - m_nWidth) > -epsilon)
695 m_chasemouse_delta_x = min_int((pointx - m_nWidth), 0) + epsilon;
698 if (pointy < epsilon)
700 m_chasemouse_delta_y = std::max(pointy, 0) - epsilon;
702 else if ((pointy - m_nHeight) > -epsilon)
704 m_chasemouse_delta_y = min_int((pointy - m_nHeight), 0) + epsilon;
707 if(m_chasemouse_delta_y != 0 || m_chasemouse_delta_x != 0)
709 //globalOutputStream() << "chasemouse motion: x=" << pointx << " y=" << pointy << "... ";
710 m_chasemouse_current_x = pointx;
711 m_chasemouse_current_y = pointy;
712 if(m_chasemouse_handler == 0)
714 //globalOutputStream() << "chasemouse timer start... ";
715 g_chasemouse_timer.start();
716 m_chasemouse_handler = g_idle_add(xywnd_chasemouse, this);
722 if(m_chasemouse_handler != 0)
724 //globalOutputStream() << "chasemouse cancel\n";
725 g_source_remove(m_chasemouse_handler);
726 m_chasemouse_handler = 0;
732 if(m_chasemouse_handler != 0)
734 //globalOutputStream() << "chasemouse cancel\n";
735 g_source_remove(m_chasemouse_handler);
736 m_chasemouse_handler = 0;
742 // =============================================================================
744 Shader* XYWnd::m_state_selected = 0;
746 void xy_update_xor_rectangle(XYWnd& self, rect_t area)
748 if(GTK_WIDGET_VISIBLE(self.GetWidget()))
750 self.m_XORRectangle.set(rectangle_from_area(area.min, area.max, self.Width(), self.Height()));
754 gboolean xywnd_button_press(GtkWidget* widget, GdkEventButton* event, XYWnd* xywnd)
756 if(event->type == GDK_BUTTON_PRESS)
758 g_pParentWnd->SetActiveXY(xywnd);
760 xywnd->ButtonState_onMouseDown(buttons_for_event_button(event));
762 xywnd->onMouseDown(WindowVector(event->x, event->y), button_for_button(event->button), modifiers_for_state(event->state));
767 gboolean xywnd_button_release(GtkWidget* widget, GdkEventButton* event, XYWnd* xywnd)
769 if(event->type == GDK_BUTTON_RELEASE)
771 xywnd->XY_MouseUp(static_cast<int>(event->x), static_cast<int>(event->y), buttons_for_event_button(event));
773 xywnd->ButtonState_onMouseUp(buttons_for_event_button(event));
778 gboolean xywnd_focus_in(GtkWidget* widget, GdkEventFocus* event, XYWnd* xywnd)
780 if(event->type == GDK_FOCUS_CHANGE)
783 g_pParentWnd->SetActiveXY(xywnd);
788 void xywnd_motion(gdouble x, gdouble y, guint state, void* data)
790 if(reinterpret_cast<XYWnd*>(data)->chaseMouseMotion(static_cast<int>(x), static_cast<int>(y)))
794 reinterpret_cast<XYWnd*>(data)->XY_MouseMoved(static_cast<int>(x), static_cast<int>(y), buttons_for_state(state));
797 gboolean xywnd_wheel_scroll(GtkWidget* widget, GdkEventScroll* event, XYWnd* xywnd)
799 if(event->direction == GDK_SCROLL_UP)
803 else if(event->direction == GDK_SCROLL_DOWN)
805 XYWnd_ZoomOut(xywnd);
810 gboolean xywnd_size_allocate(GtkWidget* widget, GtkAllocation* allocation, XYWnd* xywnd)
812 xywnd->m_nWidth = allocation->width;
813 xywnd->m_nHeight = allocation->height;
814 xywnd->updateProjection();
815 xywnd->m_window_observer->onSizeChanged(xywnd->Width(), xywnd->Height());
819 gboolean xywnd_expose(GtkWidget* widget, GdkEventExpose* event, XYWnd* xywnd)
821 if(glwidget_make_current(xywnd->GetWidget()) != FALSE)
823 if(Map_Valid(g_map) && ScreenUpdates_Enabled())
825 GlobalOpenGL_debugAssertNoErrors();
827 GlobalOpenGL_debugAssertNoErrors();
829 xywnd->m_XORRectangle.set(rectangle_t());
831 glwidget_swap_buffers(xywnd->GetWidget());
837 void XYWnd_CameraMoved(XYWnd& xywnd)
839 if(g_xywindow_globals_private.m_bCamXYUpdate)
846 m_gl_widget(glwidget_new(FALSE)),
847 m_deferredDraw(WidgetQueueDrawCaller(*m_gl_widget)),
848 m_deferred_motion(xywnd_motion, this),
850 m_window_observer(NewWindowObserver()),
851 m_XORRectangle(m_gl_widget),
852 m_chasemouse_handler(0)
857 m_bNewBrushDrag = false;
858 m_move_started = false;
859 m_zoom_started = false;
870 m_backgroundActivated = false;
877 m_entityCreate = false;
881 GlobalWindowObservers_add(m_window_observer);
882 GlobalWindowObservers_connectWidget(m_gl_widget);
884 m_window_observer->setRectangleDrawCallback(ReferenceCaller1<XYWnd, rect_t, xy_update_xor_rectangle>(*this));
885 m_window_observer->setView(m_view);
887 gtk_widget_ref(m_gl_widget);
889 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);
890 GTK_WIDGET_SET_FLAGS(m_gl_widget, GTK_CAN_FOCUS);
892 m_sizeHandler = g_signal_connect(G_OBJECT(m_gl_widget), "size_allocate", G_CALLBACK(xywnd_size_allocate), this);
893 m_exposeHandler = g_signal_connect(G_OBJECT(m_gl_widget), "expose_event", G_CALLBACK(xywnd_expose), this);
895 g_signal_connect(G_OBJECT(m_gl_widget), "button_press_event", G_CALLBACK(xywnd_button_press), this);
896 g_signal_connect(G_OBJECT(m_gl_widget), "button_release_event", G_CALLBACK(xywnd_button_release), this);
897 g_signal_connect(G_OBJECT(m_gl_widget), "focus_in_event", G_CALLBACK(xywnd_focus_in), this);
898 g_signal_connect(G_OBJECT(m_gl_widget), "motion_notify_event", G_CALLBACK(DeferredMotion::gtk_motion), &m_deferred_motion);
900 g_signal_connect(G_OBJECT(m_gl_widget), "scroll_event", G_CALLBACK(xywnd_wheel_scroll), this);
902 Map_addValidCallback(g_map, DeferredDrawOnMapValidChangedCaller(m_deferredDraw));
907 AddSceneChangeCallback(ReferenceCaller<XYWnd, &XYWnd_Update>(*this));
908 AddCameraMovedCallback(ReferenceCaller<XYWnd, &XYWnd_CameraMoved>(*this));
910 PressedButtons_connect(g_pressedButtons, m_gl_widget);
912 onMouseDown.connectLast(makeSignalHandler3(MouseDownCaller(), *this));
921 gtk_widget_destroy(GTK_WIDGET(m_mnuDrop));
925 g_signal_handler_disconnect(G_OBJECT(m_gl_widget), m_sizeHandler);
926 g_signal_handler_disconnect(G_OBJECT(m_gl_widget), m_exposeHandler);
928 gtk_widget_unref(m_gl_widget);
930 m_window_observer->release();
933 void XYWnd::captureStates()
935 m_state_selected = GlobalShaderCache().capture("$XY_OVERLAY");
938 void XYWnd::releaseStates()
940 GlobalShaderCache().release("$XY_OVERLAY");
943 const Vector3& XYWnd::GetOrigin()
948 void XYWnd::SetOrigin(const Vector3& origin)
954 void XYWnd::Scroll(int x, int y)
956 int nDim1 = (m_viewType == YZ) ? 1 : 0;
957 int nDim2 = (m_viewType == XY) ? 1 : 2;
958 m_vOrigin[nDim1] += x / m_fScale;
959 m_vOrigin[nDim2] += y / m_fScale;
964 unsigned int Clipper_buttons()
969 void XYWnd::DropClipPoint(int pointx, int pointy)
973 XY_ToPoint(pointx, pointy, point);
977 g_clip_viewtype = static_cast<VIEWTYPE>(GetViewType());
978 const int nDim = (g_clip_viewtype == YZ ) ? 0 : ( (g_clip_viewtype == XZ) ? 1 : 2 );
979 point[nDim] = mid[nDim];
980 vector3_snap(point, GetSnapGridSize());
984 void XYWnd::Clipper_OnLButtonDown(int x, int y)
986 Vector3 mousePosition;
987 XY_ToPoint(x, y , mousePosition);
988 g_pMovingClip = GlobalClipPoints_Find(mousePosition, (VIEWTYPE)m_viewType, m_fScale);
995 void XYWnd::Clipper_OnLButtonUp(int x, int y)
1003 void XYWnd::Clipper_OnMouseMoved(int x, int y)
1007 XY_ToPoint(x, y , g_pMovingClip->m_ptClip);
1008 XY_SnapToGrid(g_pMovingClip->m_ptClip);
1010 ClipperChangeNotify();
1014 void XYWnd::Clipper_Crosshair_OnMouseMoved(int x, int y)
1016 Vector3 mousePosition;
1017 XY_ToPoint(x, y , mousePosition);
1018 if(ClipMode() && GlobalClipPoints_Find(mousePosition, (VIEWTYPE)m_viewType, m_fScale) != 0)
1021 cursor = gdk_cursor_new (GDK_CROSSHAIR);
1022 gdk_window_set_cursor (m_gl_widget->window, cursor);
1023 gdk_cursor_unref (cursor);
1027 gdk_window_set_cursor (m_gl_widget->window, 0);
1031 unsigned int MoveCamera_buttons()
1033 return RAD_CONTROL | (g_glwindow_globals.m_nMouseType == ETwoButton ? RAD_RBUTTON : RAD_MBUTTON);
1036 void XYWnd_PositionCamera(XYWnd* xywnd, int x, int y, CamWnd& camwnd)
1038 Vector3 origin(Camera_getOrigin(camwnd));
1039 xywnd->XY_ToPoint(x, y, origin);
1040 xywnd->XY_SnapToGrid(origin);
1041 Camera_setOrigin(camwnd, origin);
1044 unsigned int OrientCamera_buttons()
1046 if(g_glwindow_globals.m_nMouseType == ETwoButton)
1047 return RAD_RBUTTON | RAD_SHIFT | RAD_CONTROL;
1051 void XYWnd_OrientCamera(XYWnd* xywnd, int x, int y, CamWnd& camwnd)
1053 Vector3 point = g_vector3_identity;
1054 xywnd->XY_ToPoint(x, y, point);
1055 xywnd->XY_SnapToGrid(point);
1056 vector3_subtract(point, Camera_getOrigin(camwnd));
1058 int n1 = (xywnd->GetViewType() == XY) ? 1 : 2;
1059 int n2 = (xywnd->GetViewType() == YZ) ? 1 : 0;
1060 int nAngle = (xywnd->GetViewType() == XY) ? CAMERA_YAW : CAMERA_PITCH;
1061 if (point[n1] || point[n2])
1063 Vector3 angles(Camera_getAngles(camwnd));
1064 angles[nAngle] = static_cast<float>(radians_to_degrees(atan2 (point[n1], point[n2])));
1065 Camera_setAngles(camwnd, angles);
1074 unsigned int NewBrushDrag_buttons()
1079 void XYWnd::NewBrushDrag_Begin(int x, int y)
1082 m_nNewBrushPressx = x;
1083 m_nNewBrushPressy = y;
1085 m_bNewBrushDrag = true;
1086 GlobalUndoSystem().start();
1089 void XYWnd::NewBrushDrag_End(int x, int y)
1091 if(m_NewBrushDrag != 0)
1093 GlobalUndoSystem().finish("brushDragNew");
1097 void XYWnd::NewBrushDrag(int x, int y)
1100 XY_ToPoint(m_nNewBrushPressx, m_nNewBrushPressy, mins);
1101 XY_SnapToGrid(mins);
1102 XY_ToPoint(x, y, maxs);
1103 XY_SnapToGrid(maxs);
1105 int nDim = (m_viewType == XY) ? 2 : (m_viewType == YZ) ? 0 : 1;
1107 mins[nDim] = float_snapped(Select_getWorkZone().d_work_min[nDim], GetSnapGridSize());
1108 maxs[nDim] = float_snapped(Select_getWorkZone().d_work_max[nDim], GetSnapGridSize());
1110 if (maxs[nDim] <= mins[nDim])
1111 maxs[nDim] = mins[nDim] + GetGridSize();
1113 for(int i=0 ; i<3 ; i++)
1115 if (mins[i] == maxs[i])
1116 return; // don't create a degenerate brush
1117 if (mins[i] > maxs[i])
1119 float temp = mins[i];
1125 if(m_NewBrushDrag == 0)
1127 NodeSmartReference node(GlobalBrushCreator().createBrush());
1128 Node_getTraversable(Map_FindOrInsertWorldspawn(g_map))->insert(node);
1130 scene::Path brushpath(makeReference(GlobalSceneGraph().root()));
1131 brushpath.push(makeReference(*Map_GetWorldspawn(g_map)));
1132 brushpath.push(makeReference(node.get()));
1133 selectPath(brushpath, true);
1135 m_NewBrushDrag = node.get_pointer();
1139 //Scene_BrushResize_Selected(GlobalSceneGraph(), aabb_for_minmax(mins, maxs), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()));
1140 Scene_BrushResize_Selected(GlobalSceneGraph(), aabb_for_minmax(mins, maxs),
1141 g_brush_always_caulk ?
1142 "textures/common/caulk" : TextureBrowser_GetSelectedShader(GlobalTextureBrowser()));
1145 void entitycreate_activated(GtkWidget* item)
1147 scene::Node* world_node = Map_FindWorldspawn(g_map);
1148 const char* entity_name = gtk_label_get_text(GTK_LABEL(GTK_BIN(item)->child));
1150 if(!(world_node && string_equal(entity_name, "worldspawn")))
1152 g_pParentWnd->ActiveXY()->OnEntityCreate(entity_name);
1154 GlobalRadiant().m_pfnMessageBox(GTK_WIDGET(MainFrame_getWindow()), "There's already a worldspawn in your map!"
1162 void EntityClassMenu_addItem(GtkMenu* menu, const char* name)
1164 GtkMenuItem* item = GTK_MENU_ITEM(gtk_menu_item_new_with_label(name));
1165 g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(entitycreate_activated), item);
1166 gtk_widget_show(GTK_WIDGET(item));
1167 menu_add_item(menu, item);
1170 class EntityClassMenuInserter : public EntityClassVisitor
1172 typedef std::pair<GtkMenu*, CopiedString> MenuPair;
1173 typedef std::vector<MenuPair> MenuStack;
1175 CopiedString m_previous;
1177 EntityClassMenuInserter(GtkMenu* menu)
1180 m_stack.push_back(MenuPair(menu, ""));
1182 ~EntityClassMenuInserter()
1184 if(!string_empty(m_previous.c_str()))
1186 addItem(m_previous.c_str(), "");
1189 void visit(EntityClass* e)
1191 ASSERT_MESSAGE(!string_empty(e->name()), "entity-class has no name");
1192 if(!string_empty(m_previous.c_str()))
1194 addItem(m_previous.c_str(), e->name());
1196 m_previous = e->name();
1198 void pushMenu(const CopiedString& name)
1200 GtkMenuItem* item = GTK_MENU_ITEM(gtk_menu_item_new_with_label(name.c_str()));
1201 gtk_widget_show(GTK_WIDGET(item));
1202 container_add_widget(GTK_CONTAINER(m_stack.back().first), GTK_WIDGET(item));
1204 GtkMenu* submenu = GTK_MENU(gtk_menu_new());
1205 gtk_menu_item_set_submenu(item, GTK_WIDGET(submenu));
1207 m_stack.push_back(MenuPair(submenu, name));
1213 void addItem(const char* name, const char* next)
1215 const char* underscore = strchr(name, '_');
1217 if(underscore != 0 && underscore != name)
1219 bool nextEqual = string_equal_n(name, next, (underscore + 1) - name);
1220 const char* parent = m_stack.back().second.c_str();
1222 if(!string_empty(parent)
1223 && string_length(parent) == std::size_t(underscore - name)
1224 && string_equal_n(name, parent, underscore - name)) // this is a child
1229 if(m_stack.size() == 2)
1233 pushMenu(CopiedString(StringRange(name, underscore)));
1235 else if(m_stack.size() == 2)
1240 else if(m_stack.size() == 2)
1245 EntityClassMenu_addItem(m_stack.back().first, name);
1249 void XYWnd::OnContextMenu()
1251 if (g_xywindow_globals.m_bRightClick == false)
1254 if (m_mnuDrop == 0) // first time, load it up
1256 GtkMenu* menu = m_mnuDrop = GTK_MENU(gtk_menu_new());
1258 EntityClassMenuInserter inserter(menu);
1259 GlobalEntityClassManager().forEach(inserter);
1262 gtk_menu_popup(m_mnuDrop, 0, 0, 0, 0, 1, GDK_CURRENT_TIME);
1265 FreezePointer g_xywnd_freezePointer;
1267 unsigned int Move_buttons()
1272 void XYWnd_moveDelta(int x, int y, unsigned int state, void* data)
1274 reinterpret_cast<XYWnd*>(data)->EntityCreate_MouseMove(x, y);
1275 reinterpret_cast<XYWnd*>(data)->Scroll(-x, y);
1278 gboolean XYWnd_Move_focusOut(GtkWidget* widget, GdkEventFocus* event, XYWnd* xywnd)
1284 void XYWnd::Move_Begin()
1290 m_move_started = true;
1291 g_xywnd_freezePointer.freeze_pointer(m_parent != 0 ? m_parent : MainFrame_getWindow(), XYWnd_moveDelta, this);
1292 m_move_focusOut = g_signal_connect(G_OBJECT(m_gl_widget), "focus_out_event", G_CALLBACK(XYWnd_Move_focusOut), this);
1295 void XYWnd::Move_End()
1297 m_move_started = false;
1298 g_xywnd_freezePointer.unfreeze_pointer(m_parent != 0 ? m_parent : MainFrame_getWindow());
1299 g_signal_handler_disconnect(G_OBJECT(m_gl_widget), m_move_focusOut);
1302 unsigned int Zoom_buttons()
1304 return RAD_RBUTTON | RAD_SHIFT;
1309 void XYWnd_zoomDelta(int x, int y, unsigned int state, void* data)
1315 while(abs(g_dragZoom) > 8)
1319 XYWnd_ZoomOut(reinterpret_cast<XYWnd*>(data));
1324 XYWnd_ZoomIn(reinterpret_cast<XYWnd*>(data));
1331 gboolean XYWnd_Zoom_focusOut(GtkWidget* widget, GdkEventFocus* event, XYWnd* xywnd)
1337 void XYWnd::Zoom_Begin()
1343 m_zoom_started = true;
1345 g_xywnd_freezePointer.freeze_pointer(m_parent != 0 ? m_parent : MainFrame_getWindow(), XYWnd_zoomDelta, this);
1346 m_zoom_focusOut = g_signal_connect(G_OBJECT(m_gl_widget), "focus_out_event", G_CALLBACK(XYWnd_Zoom_focusOut), this);
1349 void XYWnd::Zoom_End()
1351 m_zoom_started = false;
1352 g_xywnd_freezePointer.unfreeze_pointer(m_parent != 0 ? m_parent : MainFrame_getWindow());
1353 g_signal_handler_disconnect(G_OBJECT(m_gl_widget), m_zoom_focusOut);
1356 // makes sure the selected brush or camera is in view
1357 void XYWnd::PositionView(const Vector3& position)
1359 int nDim1 = (m_viewType == YZ) ? 1 : 0;
1360 int nDim2 = (m_viewType == XY) ? 1 : 2;
1362 m_vOrigin[nDim1] = position[nDim1];
1363 m_vOrigin[nDim2] = position[nDim2];
1367 XYWnd_Update(*this);
1370 void XYWnd::SetViewType(VIEWTYPE viewType)
1372 m_viewType = viewType;
1377 gtk_window_set_title(m_parent, ViewType_getTitle(m_viewType));
1382 inline WindowVector WindowVector_forInteger(int x, int y)
1384 return WindowVector(static_cast<float>(x), static_cast<float>(y));
1387 void XYWnd::mouseDown(const WindowVector& position, ButtonIdentifier button, ModifierFlags modifiers)
1389 XY_MouseDown(static_cast<int>(position.x()), static_cast<int>(position.y()), buttons_for_button_and_modifiers(button, modifiers));
1391 void XYWnd::XY_MouseDown (int x, int y, unsigned int buttons)
1393 if(buttons == Move_buttons())
1396 EntityCreate_MouseDown(x, y);
1398 else if(buttons == Zoom_buttons())
1402 else if(ClipMode() && buttons == Clipper_buttons())
1404 Clipper_OnLButtonDown(x, y);
1406 else if(buttons == NewBrushDrag_buttons() && GlobalSelectionSystem().countSelected() == 0)
1408 NewBrushDrag_Begin(x, y);
1410 // control mbutton = move camera
1411 else if (buttons == MoveCamera_buttons())
1413 XYWnd_PositionCamera(this, x, y, *g_pParentWnd->GetCamWnd());
1415 // mbutton = angle camera
1416 else if(buttons == OrientCamera_buttons())
1418 XYWnd_OrientCamera(this, x, y, *g_pParentWnd->GetCamWnd());
1422 m_window_observer->onMouseDown(WindowVector_forInteger(x, y), button_for_flags(buttons), modifiers_for_flags(buttons));
1426 void XYWnd::XY_MouseUp(int x, int y, unsigned int buttons)
1431 EntityCreate_MouseUp(x, y);
1433 else if(m_zoom_started)
1437 else if (ClipMode() && buttons == Clipper_buttons())
1439 Clipper_OnLButtonUp(x, y);
1441 else if (m_bNewBrushDrag)
1443 m_bNewBrushDrag = false;
1444 NewBrushDrag_End(x, y);
1448 m_window_observer->onMouseUp(WindowVector_forInteger(x, y), button_for_flags(buttons), modifiers_for_flags(buttons));
1452 void XYWnd::XY_MouseMoved (int x, int y, unsigned int buttons)
1454 // rbutton = drag xy origin
1459 else if(m_zoom_started)
1463 else if (ClipMode() && g_pMovingClip != 0)
1465 Clipper_OnMouseMoved(x, y);
1467 // lbutton without selection = drag new brush
1468 else if (m_bNewBrushDrag)
1473 // control mbutton = move camera
1474 else if (getButtonState() == MoveCamera_buttons())
1476 XYWnd_PositionCamera(this, x, y, *g_pParentWnd->GetCamWnd());
1479 // mbutton = angle camera
1480 else if (getButtonState() == OrientCamera_buttons())
1482 XYWnd_OrientCamera(this, x, y, *g_pParentWnd->GetCamWnd());
1487 m_window_observer->onMouseMotion(WindowVector_forInteger(x, y), modifiers_for_flags(buttons));
1489 m_mousePosition[0] = m_mousePosition[1] = m_mousePosition[2] = 0.0;
1490 XY_ToPoint(x, y , m_mousePosition);
1491 XY_SnapToGrid(m_mousePosition);
1493 StringOutputStream status(64);
1494 status << "x:: " << FloatFormat(m_mousePosition[0], 6, 1)
1495 << " y:: " << FloatFormat(m_mousePosition[1], 6, 1)
1496 << " z:: " << FloatFormat(m_mousePosition[2], 6, 1);
1497 g_pParentWnd->SetStatusText(g_pParentWnd->m_position_status, status.c_str());
1501 XYWnd_Update(*this);
1504 Clipper_Crosshair_OnMouseMoved(x, y);
1508 void XYWnd::EntityCreate_MouseDown(int x, int y)
1510 m_entityCreate = true;
1511 m_entityCreate_x = x;
1512 m_entityCreate_y = y;
1515 void XYWnd::EntityCreate_MouseMove(int x, int y)
1517 if(m_entityCreate && (m_entityCreate_x != x || m_entityCreate_y != y))
1519 m_entityCreate = false;
1523 void XYWnd::EntityCreate_MouseUp(int x, int y)
1527 m_entityCreate = false;
1532 inline float screen_normalised(int pos, unsigned int size)
1534 return ((2.0f * pos) / size) - 1.0f;
1537 inline float normalised_to_world(float normalised, float world_origin, float normalised2world_scale)
1539 return world_origin + normalised * normalised2world_scale;
1543 // TTimo: watch it, this doesn't init one of the 3 coords
1544 void XYWnd::XY_ToPoint (int x, int y, Vector3& point)
1546 float normalised2world_scale_x = m_nWidth / 2 / m_fScale;
1547 float normalised2world_scale_y = m_nHeight / 2 / m_fScale;
1548 if (m_viewType == XY)
1550 point[0] = normalised_to_world(screen_normalised(x, m_nWidth), m_vOrigin[0], normalised2world_scale_x);
1551 point[1] = normalised_to_world(-screen_normalised(y, m_nHeight), m_vOrigin[1], normalised2world_scale_y);
1553 else if (m_viewType == YZ)
1555 point[1] = normalised_to_world(screen_normalised(x, m_nWidth), m_vOrigin[1], normalised2world_scale_x);
1556 point[2] = normalised_to_world(-screen_normalised(y, m_nHeight), m_vOrigin[2], normalised2world_scale_y);
1560 point[0] = normalised_to_world(screen_normalised(x, m_nWidth), m_vOrigin[0], normalised2world_scale_x);
1561 point[2] = normalised_to_world(-screen_normalised(y, m_nHeight), m_vOrigin[2], normalised2world_scale_y);
1565 void XYWnd::XY_SnapToGrid(Vector3& point)
1567 if (m_viewType == XY)
1569 point[0] = float_snapped(point[0], GetSnapGridSize());
1570 point[1] = float_snapped(point[1], GetSnapGridSize());
1572 else if (m_viewType == YZ)
1574 point[1] = float_snapped(point[1], GetSnapGridSize());
1575 point[2] = float_snapped(point[2], GetSnapGridSize());
1579 point[0] = float_snapped(point[0], GetSnapGridSize());
1580 point[2] = float_snapped(point[2], GetSnapGridSize());
1584 void XYWnd::XY_LoadBackgroundImage(const char *name)
1586 const char* relative = path_make_relative(name, GlobalFileSystem().findRoot(name));
1587 if (relative == name)
1588 globalOutputStream() << "WARNING: could not extract the relative path, using full path instead\n";
1590 char fileNameWithoutExt[512];
1591 strncpy(fileNameWithoutExt, relative, sizeof(fileNameWithoutExt) - 1);
1592 fileNameWithoutExt[512 - 1] = '\0';
1593 fileNameWithoutExt[strlen(fileNameWithoutExt) - 4] = '\0';
1595 Image *image = QERApp_LoadImage(0, fileNameWithoutExt);
1597 globalOutputStream() << "Could not load texture " << fileNameWithoutExt << "\n";
1600 g_pParentWnd->ActiveXY()->m_tex = (qtexture_t*)malloc(sizeof(qtexture_t));
1601 LoadTextureRGBA(g_pParentWnd->ActiveXY()->XYWnd::m_tex, image->getRGBAPixels(), image->getWidth(), image->getHeight());
1602 globalOutputStream() << "Loaded background texture " << relative << "\n";
1603 g_pParentWnd->ActiveXY()->m_backgroundActivated = true;
1606 switch(g_pParentWnd->ActiveXY()->m_viewType)
1623 Select_GetBounds(min, max);
1624 g_pParentWnd->ActiveXY()->m_xmin = min[m_ix];
1625 g_pParentWnd->ActiveXY()->m_ymin = min[m_iy];
1626 g_pParentWnd->ActiveXY()->m_xmax = max[m_ix];
1627 g_pParentWnd->ActiveXY()->m_ymax = max[m_iy];
1630 void XYWnd::XY_DisableBackground (void)
1632 g_pParentWnd->ActiveXY()->m_backgroundActivated = false;
1633 if (g_pParentWnd->ActiveXY()->m_tex)
1634 free(g_pParentWnd->ActiveXY()->m_tex);
1635 g_pParentWnd->ActiveXY()->m_tex = NULL;
1638 void WXY_BackgroundSelect(void)
1640 bool brushesSelected = Scene_countSelectedBrushes(GlobalSceneGraph()) != 0;
1641 if (!brushesSelected) {
1642 gtk_MessageBox(0, "You have to select some brushes to get the bounding box for.\n",
1643 "No selection", eMB_OK, eMB_ICONERROR);
1647 const char *filename = file_dialog(GTK_WIDGET(MainFrame_getWindow()), TRUE, "Background Image", NULL, NULL);
1648 g_pParentWnd->ActiveXY()->XY_DisableBackground();
1650 g_pParentWnd->ActiveXY()->XY_LoadBackgroundImage(filename);
1654 ============================================================================
1658 ============================================================================
1667 double two_to_the_power(int power)
1669 return pow(2.0f, power);
1672 void XYWnd::XY_DrawAxis(void)
1674 if ( g_xywindow_globals_private.show_axis) {
1675 const char g_AxisName[3] = { 'X', 'Y', 'Z' };
1676 const int nDim1 = (m_viewType == YZ) ? 1 : 0;
1677 const int nDim2 = (m_viewType == XY) ? 1 : 2;
1678 const int w = (m_nWidth / 2 / m_fScale);
1679 const int h = (m_nHeight / 2 / m_fScale);
1681 const Vector3& colourX = (m_viewType == YZ) ? g_xywindow_globals.AxisColorY : g_xywindow_globals.AxisColorX;
1682 const Vector3& colourY = (m_viewType == XY) ? g_xywindow_globals.AxisColorY : g_xywindow_globals.AxisColorZ;
1684 // draw two lines with corresponding axis colors to highlight current view
1685 // horizontal line: nDim1 color
1687 glBegin( GL_LINES );
1688 glColor3fv (vector3_to_array(colourX));
1689 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1690 glVertex2f( m_vOrigin[nDim1] - w + 65 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1692 glVertex2f( 32 / m_fScale, 0 );
1693 glColor3fv (vector3_to_array(colourY));
1694 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1695 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 20 / m_fScale );
1697 glVertex2f( 0, 32 / m_fScale );
1700 // now print axis symbols
1701 glColor3fv (vector3_to_array(colourX));
1702 glRasterPos2f ( m_vOrigin[nDim1] - w + 55 / m_fScale, m_vOrigin[nDim2] + h - 55 / m_fScale );
1703 GlobalOpenGL().drawChar(g_AxisName[nDim1]);
1704 glRasterPos2f (28 / m_fScale, -10 / m_fScale );
1705 GlobalOpenGL().drawChar(g_AxisName[nDim1]);
1706 glColor3fv (vector3_to_array(colourY));
1707 glRasterPos2f ( m_vOrigin[nDim1] - w + 25 / m_fScale, m_vOrigin[nDim2] + h - 30 / m_fScale );
1708 GlobalOpenGL().drawChar(g_AxisName[nDim2]);
1709 glRasterPos2f ( -10 / m_fScale, 28 / m_fScale );
1710 GlobalOpenGL().drawChar(g_AxisName[nDim2]);
1714 void XYWnd::XY_DrawBackground(void)
1716 glPushAttrib(GL_ALL_ATTRIB_BITS);
1718 glEnable(GL_TEXTURE_2D);
1720 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1721 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
1722 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
1723 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
1725 glPolygonMode(GL_FRONT, GL_FILL);
1727 glBindTexture(GL_TEXTURE_2D, m_tex->texture_number);
1730 glColor4f(1.0, 1.0, 1.0, m_alpha);
1731 glTexCoord2f(0.0, 1.0);
1732 glVertex2f(m_xmin, m_ymin);
1734 glTexCoord2f(1.0, 1.0);
1735 glVertex2f(m_xmax, m_ymin);
1737 glTexCoord2f(1.0, 0.0);
1738 glVertex2f(m_xmax, m_ymax);
1740 glTexCoord2f(0.0, 0.0);
1741 glVertex2f(m_xmin, m_ymax);
1744 glBindTexture(GL_TEXTURE_2D, 0);
1749 void XYWnd::XY_DrawGrid(void) {
1750 float x, y, xb, xe, yb, ye;
1753 float step, minor_step, stepx, stepy;
1754 step = minor_step = stepx = stepy = GetGridSize();
1756 int minor_power = Grid_getPower();
1759 while ((minor_step * m_fScale) <= 4.0f) { // make sure minor grid spacing is at least 4 pixels on the screen
1763 int power = minor_power;
1764 while ((power % 3) != 0 || (step * m_fScale) <= 32.0f) { // make sure major grid spacing is at least 32 pixels on the screen
1766 step = float(two_to_the_power(power));
1768 mask = (1 << (power - minor_power)) - 1;
1769 while ((stepx * m_fScale) <= 32.0f) // text step x must be at least 32
1771 while ((stepy * m_fScale) <= 32.0f) // text step y must be at least 32
1774 a = ((GetSnapGridSize() > 0.0f) ? 1.0f : 0.3f);
1776 glDisable(GL_TEXTURE_2D);
1777 glDisable(GL_TEXTURE_1D);
1778 glDisable(GL_DEPTH_TEST);
1779 glDisable(GL_BLEND);
1782 w = (m_nWidth / 2 / m_fScale);
1783 h = (m_nHeight / 2 / m_fScale);
1785 const int nDim1 = (m_viewType == YZ) ? 1 : 0;
1786 const int nDim2 = (m_viewType == XY) ? 1 : 2;
1788 xb = m_vOrigin[nDim1] - w;
1789 if (xb < region_mins[nDim1])
1790 xb = region_mins[nDim1];
1791 xb = step * floor (xb / step);
1793 xe = m_vOrigin[nDim1] + w;
1794 if (xe > region_maxs[nDim1])
1795 xe = region_maxs[nDim1];
1796 xe = step * ceil (xe / step);
1798 yb = m_vOrigin[nDim2] - h;
1799 if (yb < region_mins[nDim2])
1800 yb = region_mins[nDim2];
1801 yb = step * floor (yb / step);
1803 ye = m_vOrigin[nDim2] + h;
1804 if (ye > region_maxs[nDim2])
1805 ye = region_maxs[nDim2];
1806 ye = step * ceil (ye / step);
1808 #define COLORS_DIFFER(a,b) \
1809 ((a)[0] != (b)[0] || \
1810 (a)[1] != (b)[1] || \
1814 // draw minor blocks
1815 if (g_xywindow_globals_private.d_showgrid || a < 1.0f) {
1819 if (COLORS_DIFFER(g_xywindow_globals.color_gridminor, g_xywindow_globals.color_gridback)) {
1820 glColor4fv(vector4_to_array(Vector4(g_xywindow_globals.color_gridminor, a)));
1824 for (x = xb ; x < xe ; x += minor_step, ++i) {
1825 if ((i & mask) != 0) {
1831 for (y = yb ; y < ye ; y += minor_step, ++i) {
1832 if ((i & mask) != 0) {
1840 // draw major blocks
1841 if (COLORS_DIFFER(g_xywindow_globals.color_gridmajor, g_xywindow_globals.color_gridminor)) {
1842 glColor4fv(vector4_to_array(Vector4(g_xywindow_globals.color_gridmajor, a)));
1845 for (x = xb ; x <= xe ; x += step) {
1849 for (y = yb ; y <= ye ; y += step) {
1857 glDisable(GL_BLEND);
1860 // draw coordinate text if needed
1861 if ( g_xywindow_globals_private.show_coordinates) {
1862 glColor4fv(vector4_to_array(Vector4(g_xywindow_globals.color_gridtext, 1.0f)));
1863 float offx = m_vOrigin[nDim2] + h - (4 + GlobalOpenGL().m_font->getPixelAscent()) / m_fScale;
1864 float offy = m_vOrigin[nDim1] - w + 4 / m_fScale;
1865 for (x = xb - fmod(xb, stepx); x <= xe ; x += stepx) {
1866 glRasterPos2f (x, offx);
1867 sprintf (text, "%g", x);
1868 GlobalOpenGL().drawString(text);
1870 for (y = yb - fmod(yb, stepy); y <= ye ; y += stepy) {
1871 glRasterPos2f (offy, y);
1872 sprintf (text, "%g", y);
1873 GlobalOpenGL().drawString(text);
1877 glColor3fv(vector3_to_array(g_xywindow_globals.color_viewname));
1879 // we do this part (the old way) only if show_axis is disabled
1880 if (!g_xywindow_globals_private.show_axis) {
1881 glRasterPos2f ( m_vOrigin[nDim1] - w + 35 / m_fScale, m_vOrigin[nDim2] + h - 20 / m_fScale );
1883 GlobalOpenGL().drawString(ViewType_getTitle(m_viewType));
1887 XYWnd::XY_DrawAxis();
1889 // show current work zone?
1890 // the work zone is used to place dropped points and brushes
1891 if (g_xywindow_globals_private.d_show_work) {
1892 glColor4f( 1.0f, 0.0f, 0.0f, 1.0f );
1893 glBegin( GL_LINES );
1894 glVertex2f( xb, Select_getWorkZone().d_work_min[nDim2] );
1895 glVertex2f( xe, Select_getWorkZone().d_work_min[nDim2] );
1896 glVertex2f( xb, Select_getWorkZone().d_work_max[nDim2] );
1897 glVertex2f( xe, Select_getWorkZone().d_work_max[nDim2] );
1898 glVertex2f( Select_getWorkZone().d_work_min[nDim1], yb );
1899 glVertex2f( Select_getWorkZone().d_work_min[nDim1], ye );
1900 glVertex2f( Select_getWorkZone().d_work_max[nDim1], yb );
1901 glVertex2f( Select_getWorkZone().d_work_max[nDim1], ye );
1911 void XYWnd::XY_DrawBlockGrid()
1913 if(Map_FindWorldspawn(g_map) == 0)
1917 const char *value = Node_getEntity(*Map_GetWorldspawn(g_map))->getKeyValue("_blocksize" );
1919 sscanf( value, "%i", &g_xywindow_globals_private.blockSize );
1921 if (!g_xywindow_globals_private.blockSize || g_xywindow_globals_private.blockSize > 65536 || g_xywindow_globals_private.blockSize < 1024)
1922 // don't use custom blocksize if it is less than the default, or greater than the maximum world coordinate
1923 g_xywindow_globals_private.blockSize = 1024;
1925 float x, y, xb, xe, yb, ye;
1929 glDisable(GL_TEXTURE_2D);
1930 glDisable(GL_TEXTURE_1D);
1931 glDisable(GL_DEPTH_TEST);
1932 glDisable(GL_BLEND);
1934 w = (m_nWidth / 2 / m_fScale);
1935 h = (m_nHeight / 2 / m_fScale);
1937 int nDim1 = (m_viewType == YZ) ? 1 : 0;
1938 int nDim2 = (m_viewType == XY) ? 1 : 2;
1940 xb = m_vOrigin[nDim1] - w;
1941 if (xb < region_mins[nDim1])
1942 xb = region_mins[nDim1];
1943 xb = static_cast<float>(g_xywindow_globals_private.blockSize * floor (xb/g_xywindow_globals_private.blockSize));
1945 xe = m_vOrigin[nDim1] + w;
1946 if (xe > region_maxs[nDim1])
1947 xe = region_maxs[nDim1];
1948 xe = static_cast<float>(g_xywindow_globals_private.blockSize * ceil (xe/g_xywindow_globals_private.blockSize));
1950 yb = m_vOrigin[nDim2] - h;
1951 if (yb < region_mins[nDim2])
1952 yb = region_mins[nDim2];
1953 yb = static_cast<float>(g_xywindow_globals_private.blockSize * floor (yb/g_xywindow_globals_private.blockSize));
1955 ye = m_vOrigin[nDim2] + h;
1956 if (ye > region_maxs[nDim2])
1957 ye = region_maxs[nDim2];
1958 ye = static_cast<float>(g_xywindow_globals_private.blockSize * ceil (ye/g_xywindow_globals_private.blockSize));
1960 // draw major blocks
1962 glColor3fv(vector3_to_array(g_xywindow_globals.color_gridblock));
1967 for (x=xb ; x<=xe ; x+=g_xywindow_globals_private.blockSize)
1973 if (m_viewType == XY)
1975 for (y=yb ; y<=ye ; y+=g_xywindow_globals_private.blockSize)
1985 // draw coordinate text if needed
1987 if (m_viewType == XY && m_fScale > .1)
1989 for (x=xb ; x<xe ; x+=g_xywindow_globals_private.blockSize)
1990 for (y=yb ; y<ye ; y+=g_xywindow_globals_private.blockSize)
1992 glRasterPos2f (x+(g_xywindow_globals_private.blockSize/2), y+(g_xywindow_globals_private.blockSize/2));
1993 sprintf (text, "%i,%i",(int)floor(x/g_xywindow_globals_private.blockSize), (int)floor(y/g_xywindow_globals_private.blockSize) );
1994 GlobalOpenGL().drawString(text);
1998 glColor4f(0, 0, 0, 0);
2001 void XYWnd::DrawCameraIcon(const Vector3& origin, const Vector3& angles)
2003 float x, y, fov, box;
2006 fov = 48 / m_fScale;
2007 box = 16 / m_fScale;
2009 if (m_viewType == XY)
2013 a = degrees_to_radians(angles[CAMERA_YAW]);
2015 else if (m_viewType == YZ)
2019 a = degrees_to_radians(angles[CAMERA_PITCH]);
2025 a = degrees_to_radians(angles[CAMERA_PITCH]);
2028 glColor3f (0.0, 0.0, 1.0);
2029 glBegin(GL_LINE_STRIP);
2030 glVertex3f (x-box,y,0);
2031 glVertex3f (x,y+(box/2),0);
2032 glVertex3f (x+box,y,0);
2033 glVertex3f (x,y-(box/2),0);
2034 glVertex3f (x-box,y,0);
2035 glVertex3f (x+box,y,0);
2038 glBegin(GL_LINE_STRIP);
2039 glVertex3f (x + static_cast<float>(fov*cos(a+c_pi/4)), y + static_cast<float>(fov*sin(a+c_pi/4)), 0);
2040 glVertex3f (x, y, 0);
2041 glVertex3f (x + static_cast<float>(fov*cos(a-c_pi/4)), y + static_cast<float>(fov*sin(a-c_pi/4)), 0);
2047 float Betwixt(float f1, float f2)
2050 return f2 + ((f1 - f2) / 2);
2052 return f1 + ((f2 - f1) / 2);
2056 // can be greatly simplified but per usual i am in a hurry
2057 // which is not an excuse, just a fact
2058 void XYWnd::PaintSizeInfo(int nDim1, int nDim2, Vector3& vMinBounds, Vector3& vMaxBounds)
2060 if(vector3_equal(vMinBounds, vMaxBounds))
2064 const char* g_pDimStrings[] = {"x:", "y:", "z:"};
2065 typedef const char* OrgStrings[2];
2066 const OrgStrings g_pOrgStrings[] = { { "x:", "y:", }, { "x:", "z:", }, { "y:", "z:", } };
2068 Vector3 vSize(vector3_subtracted(vMaxBounds, vMinBounds));
2070 glColor3f(g_xywindow_globals.color_selbrushes[0] * .65f,
2071 g_xywindow_globals.color_selbrushes[1] * .65f,
2072 g_xywindow_globals.color_selbrushes[2] * .65f);
2074 StringOutputStream dimensions(16);
2076 if (m_viewType == XY)
2080 glVertex3f(vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f);
2081 glVertex3f(vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f);
2083 glVertex3f(vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f);
2084 glVertex3f(vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f);
2086 glVertex3f(vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f);
2087 glVertex3f(vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f);
2090 glVertex3f(vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2], 0.0f);
2091 glVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f);
2093 glVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f);
2094 glVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f);
2096 glVertex3f(vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2], 0.0f);
2097 glVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f);
2101 glRasterPos3f (Betwixt(vMinBounds[nDim1], vMaxBounds[nDim1]), vMinBounds[nDim2] - 20.0f / m_fScale, 0.0f);
2102 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
2103 GlobalOpenGL().drawString(dimensions.c_str());
2106 glRasterPos3f (vMaxBounds[nDim1] + 16.0f / m_fScale, Betwixt(vMinBounds[nDim2], vMaxBounds[nDim2]), 0.0f);
2107 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
2108 GlobalOpenGL().drawString(dimensions.c_str());
2111 glRasterPos3f (vMinBounds[nDim1] + 4, vMaxBounds[nDim2] + 8 / m_fScale, 0.0f);
2112 dimensions << "(" << g_pOrgStrings[0][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[0][1] << vMaxBounds[nDim2] << ")";
2113 GlobalOpenGL().drawString(dimensions.c_str());
2115 else if (m_viewType == XZ)
2119 glVertex3f(vMinBounds[nDim1], 0, vMinBounds[nDim2] - 6.0f / m_fScale);
2120 glVertex3f(vMinBounds[nDim1], 0, vMinBounds[nDim2] - 10.0f / m_fScale);
2122 glVertex3f(vMinBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale);
2123 glVertex3f(vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale);
2125 glVertex3f(vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 6.0f / m_fScale);
2126 glVertex3f(vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale);
2129 glVertex3f(vMaxBounds[nDim1] + 6.0f / m_fScale, 0,vMinBounds[nDim2]);
2130 glVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMinBounds[nDim2]);
2132 glVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMinBounds[nDim2]);
2133 glVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMaxBounds[nDim2]);
2135 glVertex3f(vMaxBounds[nDim1] + 6.0f / m_fScale, 0,vMaxBounds[nDim2]);
2136 glVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMaxBounds[nDim2]);
2140 glRasterPos3f (Betwixt(vMinBounds[nDim1], vMaxBounds[nDim1]), 0, vMinBounds[nDim2] - 20.0f / m_fScale);
2141 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
2142 GlobalOpenGL().drawString(dimensions.c_str());
2145 glRasterPos3f (vMaxBounds[nDim1] + 16.0f / m_fScale, 0, Betwixt(vMinBounds[nDim2], vMaxBounds[nDim2]));
2146 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
2147 GlobalOpenGL().drawString(dimensions.c_str());
2150 glRasterPos3f (vMinBounds[nDim1] + 4, 0, vMaxBounds[nDim2] + 8 / m_fScale);
2151 dimensions << "(" << g_pOrgStrings[1][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[1][1] << vMaxBounds[nDim2] << ")";
2152 GlobalOpenGL().drawString(dimensions.c_str());
2158 glVertex3f(0, vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale);
2159 glVertex3f(0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale);
2161 glVertex3f(0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale);
2162 glVertex3f(0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale);
2164 glVertex3f(0, vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale);
2165 glVertex3f(0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale);
2168 glVertex3f(0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2]);
2169 glVertex3f(0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2]);
2171 glVertex3f(0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2]);
2172 glVertex3f(0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2]);
2174 glVertex3f(0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2]);
2175 glVertex3f(0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2]);
2179 glRasterPos3f (0, Betwixt(vMinBounds[nDim1], vMaxBounds[nDim1]), vMinBounds[nDim2] - 20.0f / m_fScale);
2180 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
2181 GlobalOpenGL().drawString(dimensions.c_str());
2184 glRasterPos3f (0, vMaxBounds[nDim1] + 16.0f / m_fScale, Betwixt(vMinBounds[nDim2], vMaxBounds[nDim2]));
2185 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
2186 GlobalOpenGL().drawString(dimensions.c_str());
2189 glRasterPos3f (0, vMinBounds[nDim1] + 4.0f, vMaxBounds[nDim2] + 8 / m_fScale);
2190 dimensions << "(" << g_pOrgStrings[2][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[2][1] << vMaxBounds[nDim2] << ")";
2191 GlobalOpenGL().drawString(dimensions.c_str());
2195 class XYRenderer: public Renderer
2204 unsigned int m_highlight;
2208 XYRenderer(RenderStateFlags globalstate, Shader* selected) :
2209 m_globalstate(globalstate),
2210 m_state_selected(selected)
2212 ASSERT_NOTNULL(selected);
2213 m_state_stack.push_back(state_type());
2216 void SetState(Shader* state, EStyle style)
2218 ASSERT_NOTNULL(state);
2219 if(style == eWireframeOnly)
2220 m_state_stack.back().m_state = state;
2222 const EStyle getStyle() const
2224 return eWireframeOnly;
2228 m_state_stack.push_back(m_state_stack.back());
2232 ASSERT_MESSAGE(!m_state_stack.empty(), "popping empty stack");
2233 m_state_stack.pop_back();
2235 void Highlight(EHighlightMode mode, bool bEnable = true)
2238 ? m_state_stack.back().m_highlight |= mode
2239 : m_state_stack.back().m_highlight &= ~mode;
2241 void addRenderable(const OpenGLRenderable& renderable, const Matrix4& localToWorld)
2243 if(m_state_stack.back().m_highlight & ePrimitive)
2245 m_state_selected->addRenderable(renderable, localToWorld);
2249 m_state_stack.back().m_state->addRenderable(renderable, localToWorld);
2253 void render(const Matrix4& modelview, const Matrix4& projection)
2255 GlobalShaderCache().render(m_globalstate, modelview, projection);
2258 std::vector<state_type> m_state_stack;
2259 RenderStateFlags m_globalstate;
2260 Shader* m_state_selected;
2263 void XYWnd::updateProjection()
2265 m_projection[0] = 1.0f / static_cast<float>(m_nWidth / 2);
2266 m_projection[5] = 1.0f / static_cast<float>(m_nHeight / 2);
2267 m_projection[10] = 1.0f / (g_MaxWorldCoord * m_fScale);
2269 m_projection[12] = 0.0f;
2270 m_projection[13] = 0.0f;
2271 m_projection[14] = -1.0f;
2283 m_projection[11] = 0.0f;
2285 m_projection[15] = 1.0f;
2287 m_view.Construct(m_projection, m_modelview, m_nWidth, m_nHeight);
2290 // note: modelview matrix must have a uniform scale, otherwise strange things happen when rendering the rotation manipulator.
2291 void XYWnd::updateModelview()
2293 int nDim1 = (m_viewType == YZ) ? 1 : 0;
2294 int nDim2 = (m_viewType == XY) ? 1 : 2;
2297 m_modelview[12] = -m_vOrigin[nDim1] * m_fScale;
2298 m_modelview[13] = -m_vOrigin[nDim2] * m_fScale;
2299 m_modelview[14] = g_MaxWorldCoord * m_fScale;
2305 m_modelview[0] = m_fScale;
2310 m_modelview[5] = m_fScale;
2315 m_modelview[10] = -m_fScale;
2318 m_modelview[0] = m_fScale;
2324 m_modelview[6] = m_fScale;
2327 m_modelview[9] = m_fScale;
2328 m_modelview[10] = 0;
2333 m_modelview[2] = -m_fScale;
2335 m_modelview[4] = m_fScale;
2340 m_modelview[9] = m_fScale;
2341 m_modelview[10] = 0;
2345 m_modelview[3] = m_modelview[7] = m_modelview[11] = 0;
2346 m_modelview[15] = 1;
2348 m_view.Construct(m_projection, m_modelview, m_nWidth, m_nHeight);
2357 //#define DBG_SCENEDUMP
2359 void XYWnd::XY_Draw()
2364 glViewport(0, 0, m_nWidth, m_nHeight);
2365 glClearColor (g_xywindow_globals.color_gridback[0],
2366 g_xywindow_globals.color_gridback[1],
2367 g_xywindow_globals.color_gridback[2],0);
2369 glClear(GL_COLOR_BUFFER_BIT);
2375 glMatrixMode(GL_PROJECTION);
2376 glLoadMatrixf(reinterpret_cast<const float*>(&m_projection));
2378 glMatrixMode(GL_MODELVIEW);
2380 glScalef(m_fScale, m_fScale, 1);
2381 int nDim1 = (m_viewType == YZ) ? 1 : 0;
2382 int nDim2 = (m_viewType == XY) ? 1 : 2;
2383 glTranslatef(-m_vOrigin[nDim1], -m_vOrigin[nDim2], 0);
2385 glDisable (GL_LINE_STIPPLE);
2387 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
2388 glDisableClientState(GL_NORMAL_ARRAY);
2389 glDisableClientState(GL_COLOR_ARRAY);
2390 glDisable(GL_TEXTURE_2D);
2391 glDisable(GL_LIGHTING);
2392 glDisable(GL_COLOR_MATERIAL);
2393 glDisable(GL_DEPTH_TEST);
2395 if (m_backgroundActivated)
2396 XY_DrawBackground();
2399 if ( g_xywindow_globals_private.show_blocks)
2402 glLoadMatrixf(reinterpret_cast<const float*>(&m_modelview));
2404 unsigned int globalstate = RENDER_COLOURARRAY | RENDER_COLOURWRITE | RENDER_POLYGONSMOOTH | RENDER_LINESMOOTH;
2405 if(!g_xywindow_globals.m_bNoStipple)
2407 globalstate |= RENDER_LINESTIPPLE;
2411 XYRenderer renderer(globalstate, m_state_selected);
2413 Scene_Render(renderer, m_view);
2415 GlobalOpenGL_debugAssertNoErrors();
2416 renderer.render(m_modelview, m_projection);
2417 GlobalOpenGL_debugAssertNoErrors();
2420 glDepthMask(GL_FALSE);
2422 GlobalOpenGL_debugAssertNoErrors();
2424 glLoadMatrixf(reinterpret_cast<const float*>(&m_modelview));
2426 GlobalOpenGL_debugAssertNoErrors();
2427 glDisable(GL_LINE_STIPPLE);
2428 GlobalOpenGL_debugAssertNoErrors();
2430 GlobalOpenGL_debugAssertNoErrors();
2431 if(GlobalOpenGL().GL_1_3())
2433 glActiveTexture(GL_TEXTURE0);
2434 glClientActiveTexture(GL_TEXTURE0);
2436 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
2437 GlobalOpenGL_debugAssertNoErrors();
2438 glDisableClientState(GL_NORMAL_ARRAY);
2439 GlobalOpenGL_debugAssertNoErrors();
2440 glDisableClientState(GL_COLOR_ARRAY);
2441 GlobalOpenGL_debugAssertNoErrors();
2442 glDisable(GL_TEXTURE_2D);
2443 GlobalOpenGL_debugAssertNoErrors();
2444 glDisable(GL_LIGHTING);
2445 GlobalOpenGL_debugAssertNoErrors();
2446 glDisable(GL_COLOR_MATERIAL);
2447 GlobalOpenGL_debugAssertNoErrors();
2449 GlobalOpenGL_debugAssertNoErrors();
2453 if(g_xywindow_globals_private.m_bSizePaint && GlobalSelectionSystem().countSelected() != 0)
2456 Select_GetBounds(min, max);
2457 PaintSizeInfo(nDim1, nDim2, min, max);
2462 glColor4f(0.2f, 0.9f, 0.2f, 0.8f);
2464 if (m_viewType == XY)
2466 glVertex2f(2.0f * g_MinWorldCoord, m_mousePosition[1]);
2467 glVertex2f(2.0f * g_MaxWorldCoord, m_mousePosition[1]);
2468 glVertex2f(m_mousePosition[0], 2.0f * g_MinWorldCoord);
2469 glVertex2f(m_mousePosition[0], 2.0f * g_MaxWorldCoord);
2471 else if (m_viewType == YZ)
2473 glVertex3f(m_mousePosition[0], 2.0f * g_MinWorldCoord, m_mousePosition[2]);
2474 glVertex3f(m_mousePosition[0], 2.0f * g_MaxWorldCoord, m_mousePosition[2]);
2475 glVertex3f(m_mousePosition[0], m_mousePosition[1], 2.0f * g_MinWorldCoord);
2476 glVertex3f(m_mousePosition[0], m_mousePosition[1], 2.0f * g_MaxWorldCoord);
2480 glVertex3f (2.0f * g_MinWorldCoord, m_mousePosition[1], m_mousePosition[2]);
2481 glVertex3f (2.0f * g_MaxWorldCoord, m_mousePosition[1], m_mousePosition[2]);
2482 glVertex3f(m_mousePosition[0], m_mousePosition[1], 2.0f * g_MinWorldCoord);
2483 glVertex3f(m_mousePosition[0], m_mousePosition[1], 2.0f * g_MaxWorldCoord);
2490 GlobalClipPoints_Draw(m_fScale);
2493 GlobalOpenGL_debugAssertNoErrors();
2497 glScalef(m_fScale, m_fScale, 1);
2498 glTranslatef(-m_vOrigin[nDim1], -m_vOrigin[nDim2], 0);
2500 DrawCameraIcon (Camera_getOrigin(*g_pParentWnd->GetCamWnd()), Camera_getAngles(*g_pParentWnd->GetCamWnd()));
2502 Feedback_draw2D( m_viewType );
2504 if (g_xywindow_globals_private.show_outline)
2508 glMatrixMode (GL_PROJECTION);
2510 glOrtho (0, m_nWidth, 0, m_nHeight, 0, 1);
2512 glMatrixMode (GL_MODELVIEW);
2515 // four view mode doesn't colorize
2516 if (g_pParentWnd->CurrentStyle() == MainFrame::eSplit)
2517 glColor3fv(vector3_to_array(g_xywindow_globals.color_viewname));
2523 glColor3fv(vector3_to_array(g_xywindow_globals.AxisColorX));
2526 glColor3fv(vector3_to_array(g_xywindow_globals.AxisColorY));
2529 glColor3fv(vector3_to_array(g_xywindow_globals.AxisColorZ));
2533 glBegin (GL_LINE_LOOP);
2534 glVertex2f (0.5, 0.5);
2535 glVertex2f (m_nWidth-0.5, 1);
2536 glVertex2f (m_nWidth-0.5, m_nHeight-0.5);
2537 glVertex2f (0.5, m_nHeight-0.5);
2542 GlobalOpenGL_debugAssertNoErrors();
2547 void XYWnd_MouseToPoint(XYWnd* xywnd, int x, int y, Vector3& point)
2549 xywnd->XY_ToPoint(x, y, point);
2550 xywnd->XY_SnapToGrid(point);
2552 int nDim = (xywnd->GetViewType() == XY) ? 2 : (xywnd->GetViewType() == YZ) ? 0 : 1;
2553 float fWorkMid = float_mid(Select_getWorkZone().d_work_min[nDim], Select_getWorkZone().d_work_max[nDim]);
2554 point[nDim] = float_snapped(fWorkMid, GetGridSize());
2557 void XYWnd::OnEntityCreate (const char* item)
2559 StringOutputStream command;
2560 command << "entityCreate -class " << item;
2561 UndoableCommand undo(command.c_str());
2563 XYWnd_MouseToPoint(this, m_entityCreate_x, m_entityCreate_y, point);
2564 Entity_createFromSelection(item, point);
2569 void GetFocusPosition(Vector3& position)
2571 if(GlobalSelectionSystem().countSelected() != 0)
2573 Select_GetMid(position);
2577 position = Camera_getOrigin(*g_pParentWnd->GetCamWnd());
2581 void XYWnd_Focus(XYWnd* xywnd)
2584 GetFocusPosition(position);
2585 xywnd->PositionView(position);
2588 void XY_Split_Focus()
2591 GetFocusPosition(position);
2592 if(g_pParentWnd->GetXYWnd())
2593 g_pParentWnd->GetXYWnd()->PositionView(position);
2594 if(g_pParentWnd->GetXZWnd())
2595 g_pParentWnd->GetXZWnd()->PositionView(position);
2596 if(g_pParentWnd->GetYZWnd())
2597 g_pParentWnd->GetYZWnd()->PositionView(position);
2602 if (g_pParentWnd->CurrentStyle() == MainFrame::eSplit)
2604 // cannot do this in a split window
2605 // do something else that the user may want here
2610 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2616 if (g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating)
2618 // cannot do this in a split window
2619 // do something else that the user may want here
2624 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2625 xywnd->SetViewType(XY);
2631 if (g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating)
2633 // cannot do this in a split window
2634 // do something else that the user may want here
2639 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2640 xywnd->SetViewType(XZ);
2646 if (g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating)
2648 // cannot do this in a split window
2649 // do something else that the user may want here
2654 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2655 xywnd->SetViewType(YZ);
2661 if (g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating)
2663 // cannot do this in a split window
2664 // do something else that the user may want here
2669 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2670 if (xywnd->GetViewType() == XY)
2671 xywnd->SetViewType(XZ);
2672 else if (xywnd->GetViewType() == XZ)
2673 xywnd->SetViewType(YZ);
2675 xywnd->SetViewType(XY);
2681 if (g_pParentWnd->GetXYWnd())
2682 g_pParentWnd->GetXYWnd()->SetScale(1);
2683 if (g_pParentWnd->GetXZWnd())
2684 g_pParentWnd->GetXZWnd()->SetScale(1);
2685 if (g_pParentWnd->GetYZWnd())
2686 g_pParentWnd->GetYZWnd()->SetScale(1);
2691 XYWnd_ZoomIn(g_pParentWnd->ActiveXY());
2694 // NOTE: the zoom out factor is 4/5, we could think about customizing it
2695 // we don't go below a zoom factor corresponding to 10% of the max world size
2696 // (this has to be computed against the window size)
2699 XYWnd_ZoomOut(g_pParentWnd->ActiveXY());
2704 void ToggleShowCrosshair()
2707 XY_UpdateAllWindows();
2710 void ToggleShowSizeInfo()
2712 g_xywindow_globals_private.m_bSizePaint = !g_xywindow_globals_private.m_bSizePaint;
2713 XY_UpdateAllWindows();
2716 void ToggleShowGrid()
2718 g_xywindow_globals_private.d_showgrid = !g_xywindow_globals_private.d_showgrid;
2719 XY_UpdateAllWindows();
2722 ToggleShown g_xy_top_shown(true);
2724 void XY_Top_Shown_Construct(GtkWindow* parent)
2726 g_xy_top_shown.connect(GTK_WIDGET(parent));
2729 ToggleShown g_yz_side_shown(false);
2731 void YZ_Side_Shown_Construct(GtkWindow* parent)
2733 g_yz_side_shown.connect(GTK_WIDGET(parent));
2736 ToggleShown g_xz_front_shown(false);
2738 void XZ_Front_Shown_Construct(GtkWindow* parent)
2740 g_xz_front_shown.connect(GTK_WIDGET(parent));
2744 class EntityClassMenu : public ModuleObserver
2746 std::size_t m_unrealised;
2748 EntityClassMenu() : m_unrealised(1)
2753 if(--m_unrealised == 0)
2759 if(++m_unrealised == 1)
2761 if(XYWnd::m_mnuDrop != 0)
2763 gtk_widget_destroy(GTK_WIDGET(XYWnd::m_mnuDrop));
2764 XYWnd::m_mnuDrop = 0;
2770 EntityClassMenu g_EntityClassMenu;
2775 void ShowNamesToggle()
2777 GlobalEntityCreator().setShowNames(!GlobalEntityCreator().getShowNames());
2778 XY_UpdateAllWindows();
2780 typedef FreeCaller<ShowNamesToggle> ShowNamesToggleCaller;
2781 void ShowNamesExport(const BoolImportCallback& importer)
2783 importer(GlobalEntityCreator().getShowNames());
2785 typedef FreeCaller1<const BoolImportCallback&, ShowNamesExport> ShowNamesExportCaller;
2787 void ShowAnglesToggle()
2789 GlobalEntityCreator().setShowAngles(!GlobalEntityCreator().getShowAngles());
2790 XY_UpdateAllWindows();
2792 typedef FreeCaller<ShowAnglesToggle> ShowAnglesToggleCaller;
2793 void ShowAnglesExport(const BoolImportCallback& importer)
2795 importer(GlobalEntityCreator().getShowAngles());
2797 typedef FreeCaller1<const BoolImportCallback&, ShowAnglesExport> ShowAnglesExportCaller;
2799 void ShowBlocksToggle()
2801 g_xywindow_globals_private.show_blocks ^= 1;
2802 XY_UpdateAllWindows();
2804 typedef FreeCaller<ShowBlocksToggle> ShowBlocksToggleCaller;
2805 void ShowBlocksExport(const BoolImportCallback& importer)
2807 importer(g_xywindow_globals_private.show_blocks);
2809 typedef FreeCaller1<const BoolImportCallback&, ShowBlocksExport> ShowBlocksExportCaller;
2811 void ShowCoordinatesToggle()
2813 g_xywindow_globals_private.show_coordinates ^= 1;
2814 XY_UpdateAllWindows();
2816 typedef FreeCaller<ShowCoordinatesToggle> ShowCoordinatesToggleCaller;
2817 void ShowCoordinatesExport(const BoolImportCallback& importer)
2819 importer(g_xywindow_globals_private.show_coordinates);
2821 typedef FreeCaller1<const BoolImportCallback&, ShowCoordinatesExport> ShowCoordinatesExportCaller;
2823 void ShowOutlineToggle()
2825 g_xywindow_globals_private.show_outline ^= 1;
2826 XY_UpdateAllWindows();
2828 typedef FreeCaller<ShowOutlineToggle> ShowOutlineToggleCaller;
2829 void ShowOutlineExport(const BoolImportCallback& importer)
2831 importer(g_xywindow_globals_private.show_outline);
2833 typedef FreeCaller1<const BoolImportCallback&, ShowOutlineExport> ShowOutlineExportCaller;
2835 void ShowAxesToggle()
2837 g_xywindow_globals_private.show_axis ^= 1;
2838 XY_UpdateAllWindows();
2840 typedef FreeCaller<ShowAxesToggle> ShowAxesToggleCaller;
2841 void ShowAxesExport(const BoolImportCallback& importer)
2843 importer(g_xywindow_globals_private.show_axis);
2845 typedef FreeCaller1<const BoolImportCallback&, ShowAxesExport> ShowAxesExportCaller;
2847 void ShowWorkzoneToggle()
2849 g_xywindow_globals_private.d_show_work ^= 1;
2850 XY_UpdateAllWindows();
2852 typedef FreeCaller<ShowWorkzoneToggle> ShowWorkzoneToggleCaller;
2853 void ShowWorkzoneExport(const BoolImportCallback& importer)
2855 importer(g_xywindow_globals_private.d_show_work);
2857 typedef FreeCaller1<const BoolImportCallback&, ShowWorkzoneExport> ShowWorkzoneExportCaller;
2859 ShowNamesExportCaller g_show_names_caller;
2860 BoolExportCallback g_show_names_callback(g_show_names_caller);
2861 ToggleItem g_show_names(g_show_names_callback);
2863 ShowAnglesExportCaller g_show_angles_caller;
2864 BoolExportCallback g_show_angles_callback(g_show_angles_caller);
2865 ToggleItem g_show_angles(g_show_angles_callback);
2867 ShowBlocksExportCaller g_show_blocks_caller;
2868 BoolExportCallback g_show_blocks_callback(g_show_blocks_caller);
2869 ToggleItem g_show_blocks(g_show_blocks_callback);
2871 ShowCoordinatesExportCaller g_show_coordinates_caller;
2872 BoolExportCallback g_show_coordinates_callback(g_show_coordinates_caller);
2873 ToggleItem g_show_coordinates(g_show_coordinates_callback);
2875 ShowOutlineExportCaller g_show_outline_caller;
2876 BoolExportCallback g_show_outline_callback(g_show_outline_caller);
2877 ToggleItem g_show_outline(g_show_outline_callback);
2879 ShowAxesExportCaller g_show_axes_caller;
2880 BoolExportCallback g_show_axes_callback(g_show_axes_caller);
2881 ToggleItem g_show_axes(g_show_axes_callback);
2883 ShowWorkzoneExportCaller g_show_workzone_caller;
2884 BoolExportCallback g_show_workzone_callback(g_show_workzone_caller);
2885 ToggleItem g_show_workzone(g_show_workzone_callback);
2887 void XYShow_registerCommands()
2889 GlobalToggles_insert("ShowAngles", ShowAnglesToggleCaller(), ToggleItem::AddCallbackCaller(g_show_angles));
2890 GlobalToggles_insert("ShowNames", ShowNamesToggleCaller(), ToggleItem::AddCallbackCaller(g_show_names));
2891 GlobalToggles_insert("ShowBlocks", ShowBlocksToggleCaller(), ToggleItem::AddCallbackCaller(g_show_blocks));
2892 GlobalToggles_insert("ShowCoordinates", ShowCoordinatesToggleCaller(), ToggleItem::AddCallbackCaller(g_show_coordinates));
2893 GlobalToggles_insert("ShowWindowOutline", ShowOutlineToggleCaller(), ToggleItem::AddCallbackCaller(g_show_outline));
2894 GlobalToggles_insert("ShowAxes", ShowAxesToggleCaller(), ToggleItem::AddCallbackCaller(g_show_axes));
2895 GlobalToggles_insert("ShowWorkzone", ShowWorkzoneToggleCaller(), ToggleItem::AddCallbackCaller(g_show_workzone));
2898 void XYWnd_registerShortcuts()
2900 command_connect_accelerator("ToggleCrosshairs");
2901 command_connect_accelerator("ToggleSizePaint");
2906 void Orthographic_constructPreferences(PreferencesPage& page)
2908 page.appendCheckBox("", "Solid selection boxes", g_xywindow_globals.m_bNoStipple);
2909 page.appendCheckBox("", "Display size info", g_xywindow_globals_private.m_bSizePaint);
2910 page.appendCheckBox("", "Chase mouse during drags", g_xywindow_globals_private.m_bChaseMouse);
2911 page.appendCheckBox("", "Update views on camera move", g_xywindow_globals_private.m_bCamXYUpdate);
2913 void Orthographic_constructPage(PreferenceGroup& group)
2915 PreferencesPage page(group.createPage("Orthographic", "Orthographic View Preferences"));
2916 Orthographic_constructPreferences(page);
2918 void Orthographic_registerPreferencesPage()
2920 PreferencesDialog_addSettingsPage(FreeCaller1<PreferenceGroup&, Orthographic_constructPage>());
2923 void Clipper_constructPreferences(PreferencesPage& page)
2925 page.appendCheckBox("", "Clipper tool uses caulk", g_clip_useCaulk);
2927 void Clipper_constructPage(PreferenceGroup& group)
2929 PreferencesPage page(group.createPage("Clipper", "Clipper Tool Settings"));
2930 Clipper_constructPreferences(page);
2932 void Clipper_registerPreferencesPage()
2934 PreferencesDialog_addSettingsPage(FreeCaller1<PreferenceGroup&, Clipper_constructPage>());
2938 #include "preferencesystem.h"
2939 #include "stringio.h"
2944 void ToggleShown_importBool(ToggleShown& self, bool value)
2948 typedef ReferenceCaller1<ToggleShown, bool, ToggleShown_importBool> ToggleShownImportBoolCaller;
2949 void ToggleShown_exportBool(const ToggleShown& self, const BoolImportCallback& importer)
2951 importer(self.active());
2953 typedef ConstReferenceCaller1<ToggleShown, const BoolImportCallback&, ToggleShown_exportBool> ToggleShownExportBoolCaller;
2956 void XYWindow_Construct()
2958 GlobalCommands_insert("ToggleCrosshairs", FreeCaller<ToggleShowCrosshair>(), Accelerator('X', (GdkModifierType)GDK_SHIFT_MASK));
2959 GlobalCommands_insert("ToggleSizePaint", FreeCaller<ToggleShowSizeInfo>(), Accelerator('J'));
2960 GlobalCommands_insert("ToggleGrid", FreeCaller<ToggleShowGrid>(), Accelerator('0'));
2962 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)));
2963 GlobalToggles_insert("ToggleSideView", ToggleShown::ToggleCaller(g_yz_side_shown), ToggleItem::AddCallbackCaller(g_yz_side_shown.m_item));
2964 GlobalToggles_insert("ToggleFrontView", ToggleShown::ToggleCaller(g_xz_front_shown), ToggleItem::AddCallbackCaller(g_xz_front_shown.m_item));
2965 GlobalCommands_insert("NextView", FreeCaller<XY_Next>(), Accelerator(GDK_Tab, (GdkModifierType)GDK_CONTROL_MASK));
2966 GlobalCommands_insert("ZoomIn", FreeCaller<XY_ZoomIn>(), Accelerator(GDK_Delete));
2967 GlobalCommands_insert("ZoomOut", FreeCaller<XY_ZoomOut>(), Accelerator(GDK_Insert));
2968 GlobalCommands_insert("ViewTop", FreeCaller<XY_Top>(), Accelerator(GDK_KP_Home));
2969 GlobalCommands_insert("ViewSide", FreeCaller<XY_Side>(), Accelerator(GDK_KP_Page_Down));
2970 GlobalCommands_insert("ViewFront", FreeCaller<XY_Front>(), Accelerator(GDK_KP_End));
2971 GlobalCommands_insert("Zoom100", FreeCaller<XY_Zoom100>());
2972 GlobalCommands_insert("CenterXYView", FreeCaller<XY_Focus>(), Accelerator(GDK_Tab, (GdkModifierType)(GDK_SHIFT_MASK|GDK_CONTROL_MASK)));
2974 GlobalPreferenceSystem().registerPreference("ClipCaulk", BoolImportStringCaller(g_clip_useCaulk), BoolExportStringCaller(g_clip_useCaulk));
2976 GlobalPreferenceSystem().registerPreference("NewRightClick", BoolImportStringCaller(g_xywindow_globals.m_bRightClick), BoolExportStringCaller(g_xywindow_globals.m_bRightClick));
2977 GlobalPreferenceSystem().registerPreference("ChaseMouse", BoolImportStringCaller(g_xywindow_globals_private.m_bChaseMouse), BoolExportStringCaller(g_xywindow_globals_private.m_bChaseMouse));
2978 GlobalPreferenceSystem().registerPreference("SizePainting", BoolImportStringCaller(g_xywindow_globals_private.m_bSizePaint), BoolExportStringCaller(g_xywindow_globals_private.m_bSizePaint));
2979 GlobalPreferenceSystem().registerPreference("NoStipple", BoolImportStringCaller(g_xywindow_globals.m_bNoStipple), BoolExportStringCaller(g_xywindow_globals.m_bNoStipple));
2980 GlobalPreferenceSystem().registerPreference("SI_ShowCoords", BoolImportStringCaller(g_xywindow_globals_private.show_coordinates), BoolExportStringCaller(g_xywindow_globals_private.show_coordinates));
2981 GlobalPreferenceSystem().registerPreference("SI_ShowOutlines", BoolImportStringCaller(g_xywindow_globals_private.show_outline), BoolExportStringCaller(g_xywindow_globals_private.show_outline));
2982 GlobalPreferenceSystem().registerPreference("SI_ShowAxis", BoolImportStringCaller(g_xywindow_globals_private.show_axis), BoolExportStringCaller(g_xywindow_globals_private.show_axis));
2983 GlobalPreferenceSystem().registerPreference("CamXYUpdate", BoolImportStringCaller(g_xywindow_globals_private.m_bCamXYUpdate), BoolExportStringCaller(g_xywindow_globals_private.m_bCamXYUpdate));
2984 GlobalPreferenceSystem().registerPreference("ShowWorkzone", BoolImportStringCaller(g_xywindow_globals_private.d_show_work), BoolExportStringCaller(g_xywindow_globals_private.d_show_work));
2986 GlobalPreferenceSystem().registerPreference("SI_AxisColors0", Vector3ImportStringCaller(g_xywindow_globals.AxisColorX), Vector3ExportStringCaller(g_xywindow_globals.AxisColorX));
2987 GlobalPreferenceSystem().registerPreference("SI_AxisColors1", Vector3ImportStringCaller(g_xywindow_globals.AxisColorY), Vector3ExportStringCaller(g_xywindow_globals.AxisColorY));
2988 GlobalPreferenceSystem().registerPreference("SI_AxisColors2", Vector3ImportStringCaller(g_xywindow_globals.AxisColorZ), Vector3ExportStringCaller(g_xywindow_globals.AxisColorZ));
2989 GlobalPreferenceSystem().registerPreference("SI_Colors1", Vector3ImportStringCaller(g_xywindow_globals.color_gridback), Vector3ExportStringCaller(g_xywindow_globals.color_gridback));
2990 GlobalPreferenceSystem().registerPreference("SI_Colors2", Vector3ImportStringCaller(g_xywindow_globals.color_gridminor), Vector3ExportStringCaller(g_xywindow_globals.color_gridminor));
2991 GlobalPreferenceSystem().registerPreference("SI_Colors3", Vector3ImportStringCaller(g_xywindow_globals.color_gridmajor), Vector3ExportStringCaller(g_xywindow_globals.color_gridmajor));
2992 GlobalPreferenceSystem().registerPreference("SI_Colors6", Vector3ImportStringCaller(g_xywindow_globals.color_gridblock), Vector3ExportStringCaller(g_xywindow_globals.color_gridblock));
2993 GlobalPreferenceSystem().registerPreference("SI_Colors7", Vector3ImportStringCaller(g_xywindow_globals.color_gridtext), Vector3ExportStringCaller(g_xywindow_globals.color_gridtext));
2994 GlobalPreferenceSystem().registerPreference("SI_Colors8", Vector3ImportStringCaller(g_xywindow_globals.color_brushes), Vector3ExportStringCaller(g_xywindow_globals.color_brushes));
2995 GlobalPreferenceSystem().registerPreference("SI_Colors14", Vector3ImportStringCaller(g_xywindow_globals.color_gridmajor_alt), Vector3ExportStringCaller(g_xywindow_globals.color_gridmajor_alt));
2998 GlobalPreferenceSystem().registerPreference("XZVIS", makeBoolStringImportCallback(ToggleShownImportBoolCaller(g_xz_front_shown)), makeBoolStringExportCallback(ToggleShownExportBoolCaller(g_xz_front_shown)));
2999 GlobalPreferenceSystem().registerPreference("YZVIS", makeBoolStringImportCallback(ToggleShownImportBoolCaller(g_yz_side_shown)), makeBoolStringExportCallback(ToggleShownExportBoolCaller(g_yz_side_shown)));
3001 Orthographic_registerPreferencesPage();
3002 Clipper_registerPreferencesPage();
3004 XYWnd::captureStates();
3005 GlobalEntityClassManager().attach(g_EntityClassMenu);
3008 void XYWindow_Destroy()
3010 GlobalEntityClassManager().detach(g_EntityClassMenu);
3011 XYWnd::releaseStates();