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)
481 void XYWnd_ZoomIn(XYWnd* xy)
483 float max_scale = 64;
484 float scale = xy->Scale() * 5.0f / 4.0f;
485 if(scale > max_scale)
487 if(xy->Scale() != max_scale)
489 xy->SetScale (max_scale);
499 // NOTE: the zoom out factor is 4/5, we could think about customizing it
500 // we don't go below a zoom factor corresponding to 10% of the max world size
501 // (this has to be computed against the window size)
502 void XYWnd_ZoomOut(XYWnd* xy)
504 float min_scale = MIN(xy->Width(),xy->Height()) / ( 1.1f * (g_MaxWorldCoord-g_MinWorldCoord));
505 float scale = xy->Scale() * 4.0f / 5.0f;
506 if(scale < min_scale)
508 if(xy->Scale() != min_scale)
510 xy->SetScale (min_scale);
519 VIEWTYPE GlobalXYWnd_getCurrentViewType()
521 ASSERT_NOTNULL(g_pParentWnd);
522 ASSERT_NOTNULL(g_pParentWnd->ActiveXY());
523 return g_pParentWnd->ActiveXY()->GetViewType();
526 // =============================================================================
529 bool g_bCrossHairs = false;
531 GtkMenu* XYWnd::m_mnuDrop = 0;
533 // this is disabled, and broken
534 // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=394
539 width = g_pParentWnd->ActiveXY()->Width();
540 height = g_pParentWnd->ActiveXY()->Height();
542 const char* filename;
544 filename = file_dialog(GTK_WIDGET(MainFrame_getWindow()), FALSE, "Save Image", 0, FILTER_BMP);
548 g_pParentWnd->ActiveXY()->MakeCurrent();
549 img = (unsigned char*)malloc (width*height*3);
550 glReadPixels (0,0,width,height,GL_RGB,GL_UNSIGNED_BYTE,img);
553 fp = fopen(filename, "wb");
557 unsigned long cmap, bfSize;
561 bfSize = 54 + width*height*3;
563 long byteswritten = 0;
564 long pixoff = 54 + cmap*4;
566 char m1 ='B', m2 ='M';
567 fwrite(&m1, 1, 1, fp); byteswritten++; // B
568 fwrite(&m2, 1, 1, fp); byteswritten++; // M
569 fwrite(&bfSize, 4, 1, fp); byteswritten+=4;// bfSize
570 fwrite(&res, 2, 1, fp); byteswritten+=2;// bfReserved1
571 fwrite(&res, 2, 1, fp); byteswritten+=2;// bfReserved2
572 fwrite(&pixoff, 4, 1, fp); byteswritten+=4;// bfOffBits
574 unsigned long biSize = 40, compress = 0, size = 0;
576 unsigned short planes = 1;
577 fwrite(&biSize, 4, 1, fp); byteswritten+=4;// biSize
578 fwrite(&width, 4, 1, fp); byteswritten+=4;// biWidth
579 fwrite(&height, 4, 1, fp); byteswritten+=4;// biHeight
580 fwrite(&planes, 2, 1, fp); byteswritten+=2;// biPlanes
581 fwrite(&bits, 2, 1, fp); byteswritten+=2;// biBitCount
582 fwrite(&compress, 4, 1, fp);byteswritten+=4;// biCompression
583 fwrite(&size, 4, 1, fp); byteswritten+=4;// biSizeImage
584 fwrite(&pixels, 4, 1, fp); byteswritten+=4;// biXPelsPerMeter
585 fwrite(&pixels, 4, 1, fp); byteswritten+=4;// biYPelsPerMeter
586 fwrite(&cmap, 4, 1, fp); byteswritten+=4;// biClrUsed
587 fwrite(&cmap, 4, 1, fp); byteswritten+=4;// biClrImportant
589 unsigned long widthDW = (((width*24) + 31) / 32 * 4);
590 long row, row_size = width*3;
591 for (row = 0; row < height; row++)
593 unsigned char* buf = img+row*row_size;
597 for (col = 0; col < row_size; col += 3)
599 putc(buf[col+2], fp);
600 putc(buf[col+1], fp);
603 byteswritten += row_size;
606 for (count = row_size; count < widthDW; count++)
608 putc(0, fp); // dummy
623 Timer g_chasemouse_timer;
625 void XYWnd::ChaseMouse()
627 float multiplier = g_chasemouse_timer.elapsed_msec() / 10.0f;
628 Scroll(float_to_integer(multiplier * m_chasemouse_delta_x), float_to_integer(multiplier * -m_chasemouse_delta_y));
630 //globalOutputStream() << "chasemouse: multiplier=" << multiplier << " x=" << m_chasemouse_delta_x << " y=" << m_chasemouse_delta_y << '\n';
632 XY_MouseMoved(m_chasemouse_current_x, m_chasemouse_current_y , getButtonState());
633 g_chasemouse_timer.start();
636 gboolean xywnd_chasemouse(gpointer data)
638 reinterpret_cast<XYWnd*>(data)->ChaseMouse();
642 inline const int& min_int(const int& left, const int& right)
644 return std::min(left, right);
647 bool XYWnd::chaseMouseMotion(int pointx, int pointy)
649 m_chasemouse_delta_x = 0;
650 m_chasemouse_delta_y = 0;
652 if (g_xywindow_globals_private.m_bChaseMouse && getButtonState() == RAD_LBUTTON)
654 const int epsilon = 16;
656 if (pointx < epsilon)
658 m_chasemouse_delta_x = std::max(pointx, 0) - epsilon;
660 else if ((pointx - m_nWidth) > -epsilon)
662 m_chasemouse_delta_x = min_int((pointx - m_nWidth), 0) + epsilon;
665 if (pointy < epsilon)
667 m_chasemouse_delta_y = std::max(pointy, 0) - epsilon;
669 else if ((pointy - m_nHeight) > -epsilon)
671 m_chasemouse_delta_y = min_int((pointy - m_nHeight), 0) + epsilon;
674 if(m_chasemouse_delta_y != 0 || m_chasemouse_delta_x != 0)
676 //globalOutputStream() << "chasemouse motion: x=" << pointx << " y=" << pointy << "... ";
677 m_chasemouse_current_x = pointx;
678 m_chasemouse_current_y = pointy;
679 if(m_chasemouse_handler == 0)
681 //globalOutputStream() << "chasemouse timer start... ";
682 g_chasemouse_timer.start();
683 m_chasemouse_handler = g_idle_add(xywnd_chasemouse, this);
689 if(m_chasemouse_handler != 0)
691 //globalOutputStream() << "chasemouse cancel\n";
692 g_source_remove(m_chasemouse_handler);
693 m_chasemouse_handler = 0;
699 if(m_chasemouse_handler != 0)
701 //globalOutputStream() << "chasemouse cancel\n";
702 g_source_remove(m_chasemouse_handler);
703 m_chasemouse_handler = 0;
709 // =============================================================================
711 Shader* XYWnd::m_state_selected = 0;
713 void xy_update_xor_rectangle(XYWnd& self, rect_t area)
715 if(GTK_WIDGET_VISIBLE(self.GetWidget()))
717 self.m_XORRectangle.set(rectangle_from_area(area.min, area.max, self.Width(), self.Height()));
721 gboolean xywnd_button_press(GtkWidget* widget, GdkEventButton* event, XYWnd* xywnd)
723 if(event->type == GDK_BUTTON_PRESS)
725 xywnd->XY_MouseDown(static_cast<int>(event->x), static_cast<int>(event->y), buttons_for_event_button(event));
730 gboolean xywnd_button_release(GtkWidget* widget, GdkEventButton* event, XYWnd* xywnd)
732 if(event->type == GDK_BUTTON_RELEASE)
734 xywnd->XY_MouseUp(static_cast<int>(event->x), static_cast<int>(event->y), buttons_for_event_button(event));
739 void xywnd_motion(gdouble x, gdouble y, guint state, void* data)
741 if(reinterpret_cast<XYWnd*>(data)->chaseMouseMotion(static_cast<int>(x), static_cast<int>(y)))
745 reinterpret_cast<XYWnd*>(data)->XY_MouseMoved(static_cast<int>(x), static_cast<int>(y), buttons_for_state(state));
748 gboolean xywnd_wheel_scroll(GtkWidget* widget, GdkEventScroll* event, XYWnd* xywnd)
750 if(event->direction == GDK_SCROLL_UP)
754 else if(event->direction == GDK_SCROLL_DOWN)
756 XYWnd_ZoomOut(xywnd);
761 gboolean xywnd_size_allocate(GtkWidget* widget, GtkAllocation* allocation, XYWnd* xywnd)
763 xywnd->m_nWidth = allocation->width;
764 xywnd->m_nHeight = allocation->height;
765 xywnd->updateProjection();
766 xywnd->m_window_observer->onSizeChanged(xywnd->Width(), xywnd->Height());
770 gboolean xywnd_expose(GtkWidget* widget, GdkEventExpose* event, XYWnd* xywnd)
772 if(glwidget_make_current(xywnd->GetWidget()) != FALSE)
774 if(Map_Valid(g_map) && ScreenUpdates_Enabled())
776 GlobalOpenGL_debugAssertNoErrors();
778 GlobalOpenGL_debugAssertNoErrors();
780 xywnd->m_XORRectangle.set(rectangle_t());
782 glwidget_swap_buffers(xywnd->GetWidget());
788 void XYWnd_CameraMoved(XYWnd& xywnd)
790 if(g_xywindow_globals_private.m_bCamXYUpdate)
797 m_gl_widget(glwidget_new(FALSE)),
798 m_deferredDraw(WidgetQueueDrawCaller(*m_gl_widget)),
799 m_deferred_motion(xywnd_motion, this),
801 m_window_observer(NewWindowObserver()),
802 m_XORRectangle(m_gl_widget),
803 m_chasemouse_handler(0)
808 m_bNewBrushDrag = false;
809 m_move_started = false;
810 m_zoom_started = false;
821 m_entityCreate = false;
825 GlobalWindowObservers_add(m_window_observer);
826 GlobalWindowObservers_connectWidget(m_gl_widget);
828 m_window_observer->setRectangleDrawCallback(ReferenceCaller1<XYWnd, rect_t, xy_update_xor_rectangle>(*this));
829 m_window_observer->setView(m_view);
831 gtk_widget_ref(m_gl_widget);
833 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);
834 GTK_WIDGET_SET_FLAGS(m_gl_widget, GTK_CAN_FOCUS);
836 m_sizeHandler = g_signal_connect(G_OBJECT(m_gl_widget), "size_allocate", G_CALLBACK(xywnd_size_allocate), this);
837 m_exposeHandler = g_signal_connect(G_OBJECT(m_gl_widget), "expose_event", G_CALLBACK(xywnd_expose), this);
839 g_signal_connect(G_OBJECT(m_gl_widget), "button_press_event", G_CALLBACK(xywnd_button_press), this);
840 g_signal_connect(G_OBJECT(m_gl_widget), "button_release_event", G_CALLBACK(xywnd_button_release), this);
841 g_signal_connect(G_OBJECT(m_gl_widget), "motion_notify_event", G_CALLBACK(DeferredMotion::gtk_motion), &m_deferred_motion);
843 g_signal_connect(G_OBJECT(m_gl_widget), "scroll_event", G_CALLBACK(xywnd_wheel_scroll), this);
845 Map_addValidCallback(g_map, DeferredDrawOnMapValidChangedCaller(m_deferredDraw));
849 AddSceneChangeCallback(ReferenceCaller<XYWnd, &XYWnd_Update>(*this));
850 AddCameraMovedCallback(ReferenceCaller<XYWnd, &XYWnd_CameraMoved>(*this));
852 PressedButtons_connect(g_pressedButtons, m_gl_widget);
859 gtk_widget_destroy(GTK_WIDGET(m_mnuDrop));
863 g_signal_handler_disconnect(G_OBJECT(m_gl_widget), m_sizeHandler);
864 g_signal_handler_disconnect(G_OBJECT(m_gl_widget), m_exposeHandler);
866 gtk_widget_unref(m_gl_widget);
868 m_window_observer->release();
871 void XYWnd::captureStates()
873 m_state_selected = GlobalShaderCache().capture("$XY_OVERLAY");
876 void XYWnd::releaseStates()
878 GlobalShaderCache().release("$XY_OVERLAY");
881 const Vector3& XYWnd::GetOrigin()
886 void XYWnd::SetOrigin(const Vector3& origin)
892 void XYWnd::Scroll(int x, int y)
894 int nDim1 = (m_viewType == YZ) ? 1 : 0;
895 int nDim2 = (m_viewType == XY) ? 1 : 2;
896 m_vOrigin[nDim1] += x / m_fScale;
897 m_vOrigin[nDim2] += y / m_fScale;
902 unsigned int Clipper_buttons()
907 void XYWnd::DropClipPoint(int pointx, int pointy)
911 XY_ToPoint(pointx, pointy, point);
915 g_clip_viewtype = static_cast<VIEWTYPE>(GetViewType());
916 int nDim = (g_clip_viewtype == YZ ) ? nDim = 0 : ( (g_clip_viewtype == XZ) ? nDim = 1 : nDim = 2 );
917 point[nDim] = mid[nDim];
918 vector3_snap(point, GetGridSize());
922 void XYWnd::Clipper_OnLButtonDown(int x, int y)
924 Vector3 mousePosition;
925 XY_ToPoint(x, y , mousePosition);
926 g_pMovingClip = GlobalClipPoints_Find(mousePosition, (VIEWTYPE)m_viewType, m_fScale);
933 void XYWnd::Clipper_OnLButtonUp(int x, int y)
941 void XYWnd::Clipper_OnMouseMoved(int x, int y)
945 XY_ToPoint(x, y , g_pMovingClip->m_ptClip);
946 XY_SnapToGrid(g_pMovingClip->m_ptClip);
948 ClipperChangeNotify();
952 void XYWnd::Clipper_Crosshair_OnMouseMoved(int x, int y)
954 Vector3 mousePosition;
955 XY_ToPoint(x, y , mousePosition);
956 if(ClipMode() && GlobalClipPoints_Find(mousePosition, (VIEWTYPE)m_viewType, m_fScale) != 0)
959 cursor = gdk_cursor_new (GDK_CROSSHAIR);
960 gdk_window_set_cursor (m_gl_widget->window, cursor);
961 gdk_cursor_unref (cursor);
965 gdk_window_set_cursor (m_gl_widget->window, 0);
969 unsigned int MoveCamera_buttons()
971 return RAD_CONTROL | (g_glwindow_globals.m_nMouseType == ETwoButton ? RAD_RBUTTON : RAD_MBUTTON);
974 void XYWnd_PositionCamera(XYWnd* xywnd, int x, int y, CamWnd& camwnd)
976 Vector3 origin(Camera_getOrigin(camwnd));
977 xywnd->XY_ToPoint(x, y, origin);
978 xywnd->XY_SnapToGrid(origin);
979 Camera_setOrigin(camwnd, origin);
982 unsigned int OrientCamera_buttons()
984 if(g_glwindow_globals.m_nMouseType == ETwoButton)
985 return RAD_RBUTTON | RAD_SHIFT | RAD_CONTROL;
989 void XYWnd_OrientCamera(XYWnd* xywnd, int x, int y, CamWnd& camwnd)
991 Vector3 point = g_vector3_identity;
992 xywnd->XY_ToPoint(x, y, point);
993 xywnd->XY_SnapToGrid(point);
994 vector3_subtract(point, Camera_getOrigin(camwnd));
996 int n1 = (xywnd->GetViewType() == XY) ? 1 : 2;
997 int n2 = (xywnd->GetViewType() == YZ) ? 1 : 0;
998 int nAngle = (xywnd->GetViewType() == XY) ? CAMERA_YAW : CAMERA_PITCH;
999 if (point[n1] || point[n2])
1001 Vector3 angles(Camera_getAngles(camwnd));
1002 angles[nAngle] = static_cast<float>(radians_to_degrees(atan2 (point[n1], point[n2])));
1003 Camera_setAngles(camwnd, angles);
1012 unsigned int NewBrushDrag_buttons()
1017 void XYWnd::NewBrushDrag_Begin(int x, int y)
1020 m_nNewBrushPressx = x;
1021 m_nNewBrushPressy = y;
1023 m_bNewBrushDrag = true;
1024 GlobalUndoSystem().start();
1027 void XYWnd::NewBrushDrag_End(int x, int y)
1029 if(m_NewBrushDrag != 0)
1031 GlobalUndoSystem().finish("brushDragNew");
1035 void XYWnd::NewBrushDrag(int x, int y)
1038 XY_ToPoint(m_nNewBrushPressx, m_nNewBrushPressy, mins);
1039 XY_SnapToGrid(mins);
1040 XY_ToPoint(x, y, maxs);
1041 XY_SnapToGrid(maxs);
1043 int nDim = (m_viewType == XY) ? 2 : (m_viewType == YZ) ? 0 : 1;
1045 mins[nDim] = float_snapped(Select_getWorkZone().d_work_min[nDim], GetGridSize());
1046 maxs[nDim] = float_snapped(Select_getWorkZone().d_work_max[nDim], GetGridSize());
1048 if (maxs[nDim] <= mins[nDim])
1049 maxs[nDim] = mins[nDim] + GetGridSize();
1051 for(int i=0 ; i<3 ; i++)
1053 if (mins[i] == maxs[i])
1054 return; // don't create a degenerate brush
1055 if (mins[i] > maxs[i])
1057 float temp = mins[i];
1063 if(m_NewBrushDrag == 0)
1065 NodeSmartReference node(GlobalBrushCreator().createBrush());
1066 Node_getTraversable(Map_FindOrInsertWorldspawn(g_map))->insert(node);
1068 scene::Path brushpath(makeReference(GlobalSceneGraph().root()));
1069 brushpath.push(makeReference(*Map_GetWorldspawn(g_map)));
1070 brushpath.push(makeReference(node.get()));
1071 selectPath(brushpath, true);
1073 m_NewBrushDrag = node.get_pointer();
1076 Scene_BrushResize_Selected(GlobalSceneGraph(), aabb_for_minmax(mins, maxs), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()));
1079 void entitycreate_activated(GtkWidget* item)
1081 g_pParentWnd->ActiveXY()->OnEntityCreate(gtk_label_get_text(GTK_LABEL(GTK_BIN(item)->child)));
1084 void EntityClassMenu_addItem(GtkMenu* menu, const char* name)
1086 GtkMenuItem* item = GTK_MENU_ITEM(gtk_menu_item_new_with_label(name));
1087 g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(entitycreate_activated), item);
1088 gtk_widget_show(GTK_WIDGET(item));
1089 menu_add_item(menu, item);
1092 class EntityClassMenuInserter : public EntityClassVisitor
1094 typedef std::pair<GtkMenu*, CopiedString> MenuPair;
1095 typedef std::vector<MenuPair> MenuStack;
1097 CopiedString m_previous;
1099 EntityClassMenuInserter(GtkMenu* menu)
1102 m_stack.push_back(MenuPair(menu, ""));
1104 ~EntityClassMenuInserter()
1106 if(!string_empty(m_previous.c_str()))
1108 addItem(m_previous.c_str(), "");
1111 void visit(EntityClass* e)
1113 ASSERT_MESSAGE(!string_empty(e->name()), "entity-class has no name");
1114 if(!string_empty(m_previous.c_str()))
1116 addItem(m_previous.c_str(), e->name());
1118 m_previous = e->name();
1120 void pushMenu(const CopiedString& name)
1122 GtkMenuItem* item = GTK_MENU_ITEM(gtk_menu_item_new_with_label(name.c_str()));
1123 gtk_widget_show(GTK_WIDGET(item));
1124 container_add_widget(GTK_CONTAINER(m_stack.back().first), GTK_WIDGET(item));
1126 GtkMenu* submenu = GTK_MENU(gtk_menu_new());
1127 gtk_menu_item_set_submenu(item, GTK_WIDGET(submenu));
1129 m_stack.push_back(MenuPair(submenu, name));
1135 void addItem(const char* name, const char* next)
1137 const char* underscore = strchr(name, '_');
1139 if(underscore != 0 && underscore != name)
1141 bool nextEqual = string_equal_n(name, next, (underscore + 1) - name);
1142 const char* parent = m_stack.back().second.c_str();
1144 if(!string_empty(parent)
1145 && string_length(parent) == std::size_t(underscore - name)
1146 && string_equal_n(name, parent, underscore - name)) // this is a child
1151 if(m_stack.size() == 2)
1155 pushMenu(CopiedString(name, underscore));
1157 else if(m_stack.size() == 2)
1162 else if(m_stack.size() == 2)
1167 EntityClassMenu_addItem(m_stack.back().first, name);
1171 void XYWnd::OnContextMenu()
1173 if (g_xywindow_globals.m_bRightClick == false)
1176 if (m_mnuDrop == 0) // first time, load it up
1178 GtkMenu* menu = m_mnuDrop = GTK_MENU(gtk_menu_new());
1180 EntityClassMenuInserter inserter(menu);
1181 GlobalEntityClassManager().forEach(inserter);
1184 gtk_menu_popup(m_mnuDrop, 0, 0, 0, 0, 1, GDK_CURRENT_TIME);
1187 FreezePointer g_xywnd_freezePointer;
1189 unsigned int Move_buttons()
1194 void XYWnd_moveDelta(int x, int y, unsigned int state, void* data)
1196 reinterpret_cast<XYWnd*>(data)->EntityCreate_MouseMove(x, y);
1197 reinterpret_cast<XYWnd*>(data)->Scroll(-x, y);
1200 gboolean XYWnd_Move_focusOut(GtkWidget* widget, GdkEventFocus* event, XYWnd* xywnd)
1206 void XYWnd::Move_Begin()
1212 m_move_started = true;
1213 g_xywnd_freezePointer.freeze_pointer(m_parent != 0 ? m_parent : MainFrame_getWindow(), XYWnd_moveDelta, this);
1214 m_move_focusOut = g_signal_connect(G_OBJECT(m_gl_widget), "focus_out_event", G_CALLBACK(XYWnd_Move_focusOut), this);
1217 void XYWnd::Move_End()
1219 m_move_started = false;
1220 g_xywnd_freezePointer.unfreeze_pointer(m_parent != 0 ? m_parent : MainFrame_getWindow());
1221 g_signal_handler_disconnect(G_OBJECT(m_gl_widget), m_move_focusOut);
1224 unsigned int Zoom_buttons()
1226 return RAD_RBUTTON | RAD_SHIFT;
1231 void XYWnd_zoomDelta(int x, int y, unsigned int state, void* data)
1237 while(abs(g_dragZoom) > 8)
1241 XYWnd_ZoomOut(reinterpret_cast<XYWnd*>(data));
1246 XYWnd_ZoomIn(reinterpret_cast<XYWnd*>(data));
1253 gboolean XYWnd_Zoom_focusOut(GtkWidget* widget, GdkEventFocus* event, XYWnd* xywnd)
1259 void XYWnd::Zoom_Begin()
1265 m_zoom_started = true;
1267 g_xywnd_freezePointer.freeze_pointer(m_parent != 0 ? m_parent : MainFrame_getWindow(), XYWnd_zoomDelta, this);
1268 m_zoom_focusOut = g_signal_connect(G_OBJECT(m_gl_widget), "focus_out_event", G_CALLBACK(XYWnd_Zoom_focusOut), this);
1271 void XYWnd::Zoom_End()
1273 m_zoom_started = false;
1274 g_xywnd_freezePointer.unfreeze_pointer(m_parent != 0 ? m_parent : MainFrame_getWindow());
1275 g_signal_handler_disconnect(G_OBJECT(m_gl_widget), m_zoom_focusOut);
1278 // makes sure the selected brush or camera is in view
1279 void XYWnd::PositionView(const Vector3& position)
1281 int nDim1 = (m_viewType == YZ) ? 1 : 0;
1282 int nDim2 = (m_viewType == XY) ? 1 : 2;
1284 m_vOrigin[nDim1] = position[nDim1];
1285 m_vOrigin[nDim2] = position[nDim2];
1289 XYWnd_Update(*this);
1292 void XYWnd::SetViewType(VIEWTYPE viewType)
1294 m_viewType = viewType;
1299 gtk_window_set_title(m_parent, ViewType_getTitle(m_viewType));
1304 inline WindowVector WindowVector_forInteger(int x, int y)
1306 return WindowVector(static_cast<float>(x), static_cast<float>(y));
1309 void XYWnd::XY_MouseDown (int x, int y, unsigned int buttons)
1311 g_pParentWnd->SetActiveXY(this);
1313 ButtonState_onMouseDown(buttons);
1315 if(buttons == Move_buttons())
1318 EntityCreate_MouseDown(x, y);
1320 else if(buttons == Zoom_buttons())
1324 else if(ClipMode() && buttons == Clipper_buttons())
1326 Clipper_OnLButtonDown(x, y);
1328 else if(buttons == NewBrushDrag_buttons() && GlobalSelectionSystem().countSelected() == 0)
1330 NewBrushDrag_Begin(x, y);
1332 // control mbutton = move camera
1333 else if (buttons == MoveCamera_buttons())
1335 XYWnd_PositionCamera(this, x, y, *g_pParentWnd->GetCamWnd());
1337 // mbutton = angle camera
1338 else if(buttons == OrientCamera_buttons())
1340 XYWnd_OrientCamera(this, x, y, *g_pParentWnd->GetCamWnd());
1344 m_window_observer->onMouseDown(WindowVector_forInteger(x, y), button_for_flags(buttons), modifiers_for_flags(buttons));
1348 void XYWnd::XY_MouseUp(int x, int y, unsigned int buttons)
1353 EntityCreate_MouseUp(x, y);
1355 else if(m_zoom_started)
1359 else if (ClipMode() && buttons == Clipper_buttons())
1361 Clipper_OnLButtonUp(x, y);
1363 else if (m_bNewBrushDrag)
1365 m_bNewBrushDrag = false;
1366 NewBrushDrag_End(x, y);
1370 m_window_observer->onMouseUp(WindowVector_forInteger(x, y), button_for_flags(buttons), modifiers_for_flags(buttons));
1373 ButtonState_onMouseUp(buttons);
1376 void XYWnd::XY_MouseMoved (int x, int y, unsigned int buttons)
1378 // rbutton = drag xy origin
1383 else if(m_zoom_started)
1387 else if (ClipMode() && g_pMovingClip != 0)
1389 Clipper_OnMouseMoved(x, y);
1391 // lbutton without selection = drag new brush
1392 else if (m_bNewBrushDrag)
1397 // control mbutton = move camera
1398 else if (getButtonState() == MoveCamera_buttons())
1400 XYWnd_PositionCamera(this, x, y, *g_pParentWnd->GetCamWnd());
1403 // mbutton = angle camera
1404 else if (getButtonState() == OrientCamera_buttons())
1406 XYWnd_OrientCamera(this, x, y, *g_pParentWnd->GetCamWnd());
1411 m_window_observer->onMouseMotion(WindowVector_forInteger(x, y), modifiers_for_flags(buttons));
1413 m_mousePosition[0] = m_mousePosition[1] = m_mousePosition[2] = 0.0;
1414 XY_ToPoint(x, y , m_mousePosition);
1415 XY_SnapToGrid(m_mousePosition);
1417 StringOutputStream status(64);
1418 status << "x:: " << FloatFormat(m_mousePosition[0], 6, 1)
1419 << " y:: " << FloatFormat(m_mousePosition[1], 6, 1)
1420 << " z:: " << FloatFormat(m_mousePosition[2], 6, 1);
1421 g_pParentWnd->SetStatusText(g_pParentWnd->m_position_status, status.c_str());
1425 XYWnd_Update(*this);
1428 Clipper_Crosshair_OnMouseMoved(x, y);
1432 void XYWnd::EntityCreate_MouseDown(int x, int y)
1434 m_entityCreate = true;
1435 m_entityCreate_x = x;
1436 m_entityCreate_y = y;
1439 void XYWnd::EntityCreate_MouseMove(int x, int y)
1441 if(m_entityCreate && (m_entityCreate_x != x || m_entityCreate_y != y))
1443 m_entityCreate = false;
1447 void XYWnd::EntityCreate_MouseUp(int x, int y)
1451 m_entityCreate = false;
1456 inline float screen_normalised(int pos, unsigned int size)
1458 return ((2.0f * pos) / size) - 1.0f;
1461 inline float normalised_to_world(float normalised, float world_origin, float normalised2world_scale)
1463 return world_origin + normalised * normalised2world_scale;
1467 // TTimo: watch it, this doesn't init one of the 3 coords
1468 void XYWnd::XY_ToPoint (int x, int y, Vector3& point)
1470 float normalised2world_scale_x = m_nWidth / 2 / m_fScale;
1471 float normalised2world_scale_y = m_nHeight / 2 / m_fScale;
1472 if (m_viewType == XY)
1474 point[0] = normalised_to_world(screen_normalised(x, m_nWidth), m_vOrigin[0], normalised2world_scale_x);
1475 point[1] = normalised_to_world(-screen_normalised(y, m_nHeight), m_vOrigin[1], normalised2world_scale_y);
1477 else if (m_viewType == YZ)
1479 point[1] = normalised_to_world(screen_normalised(x, m_nWidth), m_vOrigin[1], normalised2world_scale_x);
1480 point[2] = normalised_to_world(-screen_normalised(y, m_nHeight), m_vOrigin[2], normalised2world_scale_y);
1484 point[0] = normalised_to_world(screen_normalised(x, m_nWidth), m_vOrigin[0], normalised2world_scale_x);
1485 point[2] = normalised_to_world(-screen_normalised(y, m_nHeight), m_vOrigin[2], normalised2world_scale_y);
1489 void XYWnd::XY_SnapToGrid(Vector3& point)
1491 if (m_viewType == XY)
1493 point[0] = float_snapped(point[0], GetGridSize());
1494 point[1] = float_snapped(point[1], GetGridSize());
1496 else if (m_viewType == YZ)
1498 point[1] = float_snapped(point[1], GetGridSize());
1499 point[2] = float_snapped(point[2], GetGridSize());
1503 point[0] = float_snapped(point[0], GetGridSize());
1504 point[2] = float_snapped(point[2], GetGridSize());
1509 ============================================================================
1513 ============================================================================
1522 double two_to_the_power(int power)
1524 return pow(2.0f, power);
1527 void XYWnd::XY_DrawGrid()
1529 float x, y, xb, xe, yb, ye;
1532 float step, minor_step, stepx, stepy;
1533 step = minor_step = stepx = stepy = GetGridSize();
1535 int minor_power = Grid_getPower();
1538 while((minor_step * m_fScale) <= 4.0f) // make sure minor grid spacing is at least 4 pixels on the screen
1543 int power = minor_power;
1544 while((power % 3) != 0 || (step * m_fScale) <= 32.0f) // make sure major grid spacing is at least 32 pixels on the screen
1547 step = float(two_to_the_power(power));
1549 mask = (1 << (power - minor_power)) - 1;
1550 while ((stepx * m_fScale) <= 32.0f) // text step x must be at least 32
1552 while ((stepy * m_fScale) <= 32.0f) // text step y must be at least 32
1556 glDisable(GL_TEXTURE_2D);
1557 glDisable(GL_TEXTURE_1D);
1558 glDisable(GL_DEPTH_TEST);
1559 glDisable(GL_BLEND);
1562 w = (m_nWidth / 2 / m_fScale);
1563 h = (m_nHeight / 2 / m_fScale);
1565 int nDim1 = (m_viewType == YZ) ? 1 : 0;
1566 int nDim2 = (m_viewType == XY) ? 1 : 2;
1568 xb = m_vOrigin[nDim1] - w;
1569 if (xb < region_mins[nDim1])
1570 xb = region_mins[nDim1];
1571 xb = step * floor (xb/step);
1573 xe = m_vOrigin[nDim1] + w;
1574 if (xe > region_maxs[nDim1])
1575 xe = region_maxs[nDim1];
1576 xe = step * ceil (xe/step);
1578 yb = m_vOrigin[nDim2] - h;
1579 if (yb < region_mins[nDim2])
1580 yb = region_mins[nDim2];
1581 yb = step * floor (yb/step);
1583 ye = m_vOrigin[nDim2] + h;
1584 if (ye > region_maxs[nDim2])
1585 ye = region_maxs[nDim2];
1586 ye = step * ceil (ye/step);
1588 #define COLORS_DIFFER(a,b) \
1589 ((a)[0] != (b)[0] || \
1590 (a)[1] != (b)[1] || \
1594 // draw minor blocks
1595 if (g_xywindow_globals_private.d_showgrid)
1597 if (COLORS_DIFFER(g_xywindow_globals.color_gridminor, g_xywindow_globals.color_gridback))
1599 glColor3fv(vector3_to_array(g_xywindow_globals.color_gridminor));
1603 for (x = xb ; x < xe ; x += minor_step, ++i)
1612 for (y = yb ; y < ye ; y += minor_step, ++i)
1623 // draw major blocks
1624 if (COLORS_DIFFER(g_xywindow_globals.color_gridmajor, g_xywindow_globals.color_gridback))
1626 glColor3fv(vector3_to_array(g_xywindow_globals.color_gridmajor));
1629 for (x=xb ; x<=xe ; x+=step)
1634 for (y=yb ; y<=ye ; y+=step)
1643 // draw coordinate text if needed
1644 if ( g_xywindow_globals_private.show_coordinates)
1646 glColor3fv(vector3_to_array(g_xywindow_globals.color_gridtext));
1647 float offx = m_vOrigin[nDim2] + h - 6 / m_fScale, offy = m_vOrigin[nDim1] - w + 1 / m_fScale;
1648 for (x = xb - fmod(xb, stepx); x <= xe ; x += stepx)
1650 glRasterPos2f (x, offx);
1651 sprintf (text, "%g", x);
1652 GlobalOpenGL().drawString(text);
1654 for (y = yb - fmod(yb, stepy); y <= ye ; y += stepy)
1656 glRasterPos2f (offy, y);
1657 sprintf (text, "%g", y);
1658 GlobalOpenGL().drawString(text);
1662 glColor3fv(vector3_to_array(g_xywindow_globals.color_viewname));
1664 // we do this part (the old way) only if show_axis is disabled
1665 if (!g_xywindow_globals_private.show_axis)
1667 glRasterPos2f ( m_vOrigin[nDim1] - w + 35 / m_fScale, m_vOrigin[nDim2] + h - 20 / m_fScale );
1669 GlobalOpenGL().drawString(ViewType_getTitle(m_viewType));
1673 if ( g_xywindow_globals_private.show_axis)
1675 const char g_AxisName[3] = { 'X', 'Y', 'Z' };
1677 const Vector3& colourX = (m_viewType == YZ) ? g_xywindow_globals.AxisColorY : g_xywindow_globals.AxisColorX;
1678 const Vector3& colourY = (m_viewType == XY) ? g_xywindow_globals.AxisColorY : g_xywindow_globals.AxisColorZ;
1680 // draw two lines with corresponding axis colors to highlight current view
1681 // horizontal line: nDim1 color
1683 glBegin( GL_LINES );
1684 glColor3fv (vector3_to_array(colourX));
1685 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1686 glVertex2f( m_vOrigin[nDim1] - w + 65 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1688 glVertex2f( 32 / m_fScale, 0 );
1689 glColor3fv (vector3_to_array(colourY));
1690 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1691 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 20 / m_fScale );
1693 glVertex2f( 0, 32 / m_fScale );
1696 // now print axis symbols
1697 glColor3fv (vector3_to_array(colourX));
1698 glRasterPos2f ( m_vOrigin[nDim1] - w + 55 / m_fScale, m_vOrigin[nDim2] + h - 55 / m_fScale );
1699 GlobalOpenGL().drawChar(g_AxisName[nDim1]);
1700 glRasterPos2f (28 / m_fScale, -10 / m_fScale );
1701 GlobalOpenGL().drawChar(g_AxisName[nDim1]);
1702 glColor3fv (vector3_to_array(colourY));
1703 glRasterPos2f ( m_vOrigin[nDim1] - w + 25 / m_fScale, m_vOrigin[nDim2] + h - 30 / m_fScale );
1704 GlobalOpenGL().drawChar(g_AxisName[nDim2]);
1705 glRasterPos2f ( -10 / m_fScale, 28 / m_fScale );
1706 GlobalOpenGL().drawChar(g_AxisName[nDim2]);
1710 // show current work zone?
1711 // the work zone is used to place dropped points and brushes
1712 if (g_xywindow_globals_private.d_show_work)
1714 glColor3f( 1.0f, 0.0f, 0.0f );
1715 glBegin( GL_LINES );
1716 glVertex2f( xb, Select_getWorkZone().d_work_min[nDim2] );
1717 glVertex2f( xe, Select_getWorkZone().d_work_min[nDim2] );
1718 glVertex2f( xb, Select_getWorkZone().d_work_max[nDim2] );
1719 glVertex2f( xe, Select_getWorkZone().d_work_max[nDim2] );
1720 glVertex2f( Select_getWorkZone().d_work_min[nDim1], yb );
1721 glVertex2f( Select_getWorkZone().d_work_min[nDim1], ye );
1722 glVertex2f( Select_getWorkZone().d_work_max[nDim1], yb );
1723 glVertex2f( Select_getWorkZone().d_work_max[nDim1], ye );
1733 void XYWnd::XY_DrawBlockGrid()
1735 if(Map_FindWorldspawn(g_map) == 0)
1739 const char *value = Node_getEntity(*Map_GetWorldspawn(g_map))->getKeyValue("_blocksize" );
1741 sscanf( value, "%i", &g_xywindow_globals_private.blockSize );
1743 if (!g_xywindow_globals_private.blockSize || g_xywindow_globals_private.blockSize > 65536 || g_xywindow_globals_private.blockSize < 1024)
1744 // don't use custom blocksize if it is less than the default, or greater than the maximum world coordinate
1745 g_xywindow_globals_private.blockSize = 1024;
1747 float x, y, xb, xe, yb, ye;
1751 glDisable(GL_TEXTURE_2D);
1752 glDisable(GL_TEXTURE_1D);
1753 glDisable(GL_DEPTH_TEST);
1754 glDisable(GL_BLEND);
1756 w = (m_nWidth / 2 / m_fScale);
1757 h = (m_nHeight / 2 / m_fScale);
1759 int nDim1 = (m_viewType == YZ) ? 1 : 0;
1760 int nDim2 = (m_viewType == XY) ? 1 : 2;
1762 xb = m_vOrigin[nDim1] - w;
1763 if (xb < region_mins[nDim1])
1764 xb = region_mins[nDim1];
1765 xb = static_cast<float>(g_xywindow_globals_private.blockSize * floor (xb/g_xywindow_globals_private.blockSize));
1767 xe = m_vOrigin[nDim1] + w;
1768 if (xe > region_maxs[nDim1])
1769 xe = region_maxs[nDim1];
1770 xe = static_cast<float>(g_xywindow_globals_private.blockSize * ceil (xe/g_xywindow_globals_private.blockSize));
1772 yb = m_vOrigin[nDim2] - h;
1773 if (yb < region_mins[nDim2])
1774 yb = region_mins[nDim2];
1775 yb = static_cast<float>(g_xywindow_globals_private.blockSize * floor (yb/g_xywindow_globals_private.blockSize));
1777 ye = m_vOrigin[nDim2] + h;
1778 if (ye > region_maxs[nDim2])
1779 ye = region_maxs[nDim2];
1780 ye = static_cast<float>(g_xywindow_globals_private.blockSize * ceil (ye/g_xywindow_globals_private.blockSize));
1782 // draw major blocks
1784 glColor3fv(vector3_to_array(g_xywindow_globals.color_gridblock));
1789 for (x=xb ; x<=xe ; x+=g_xywindow_globals_private.blockSize)
1795 if (m_viewType == XY)
1797 for (y=yb ; y<=ye ; y+=g_xywindow_globals_private.blockSize)
1807 // draw coordinate text if needed
1809 if (m_viewType == XY && m_fScale > .1)
1811 for (x=xb ; x<xe ; x+=g_xywindow_globals_private.blockSize)
1812 for (y=yb ; y<ye ; y+=g_xywindow_globals_private.blockSize)
1814 glRasterPos2f (x+(g_xywindow_globals_private.blockSize/2), y+(g_xywindow_globals_private.blockSize/2));
1815 sprintf (text, "%i,%i",(int)floor(x/g_xywindow_globals_private.blockSize), (int)floor(y/g_xywindow_globals_private.blockSize) );
1816 GlobalOpenGL().drawString(text);
1820 glColor4f(0, 0, 0, 0);
1823 void XYWnd::DrawCameraIcon(const Vector3& origin, const Vector3& angles)
1825 float x, y, fov, box;
1828 fov = 48 / m_fScale;
1829 box = 16 / m_fScale;
1831 if (m_viewType == XY)
1835 a = degrees_to_radians(angles[CAMERA_YAW]);
1837 else if (m_viewType == YZ)
1841 a = degrees_to_radians(angles[CAMERA_PITCH]);
1847 a = degrees_to_radians(angles[CAMERA_PITCH]);
1850 glColor3f (0.0, 0.0, 1.0);
1851 glBegin(GL_LINE_STRIP);
1852 glVertex3f (x-box,y,0);
1853 glVertex3f (x,y+(box/2),0);
1854 glVertex3f (x+box,y,0);
1855 glVertex3f (x,y-(box/2),0);
1856 glVertex3f (x-box,y,0);
1857 glVertex3f (x+box,y,0);
1860 glBegin(GL_LINE_STRIP);
1861 glVertex3f (x + static_cast<float>(fov*cos(a+c_pi/4)), y + static_cast<float>(fov*sin(a+c_pi/4)), 0);
1862 glVertex3f (x, y, 0);
1863 glVertex3f (x + static_cast<float>(fov*cos(a-c_pi/4)), y + static_cast<float>(fov*sin(a-c_pi/4)), 0);
1869 float Betwixt(float f1, float f2)
1872 return f2 + ((f1 - f2) / 2);
1874 return f1 + ((f2 - f1) / 2);
1878 // can be greatly simplified but per usual i am in a hurry
1879 // which is not an excuse, just a fact
1880 void XYWnd::PaintSizeInfo(int nDim1, int nDim2, Vector3& vMinBounds, Vector3& vMaxBounds)
1882 if(vector3_equal(vMinBounds, vMaxBounds))
1886 const char* g_pDimStrings[] = {"x:", "y:", "z:"};
1887 typedef const char* OrgStrings[2];
1888 const OrgStrings g_pOrgStrings[] = { { "x:", "y:", }, { "x:", "z:", }, { "y:", "z:", } };
1890 Vector3 vSize(vector3_subtracted(vMaxBounds, vMinBounds));
1892 glColor3f(g_xywindow_globals.color_selbrushes[0] * .65f,
1893 g_xywindow_globals.color_selbrushes[1] * .65f,
1894 g_xywindow_globals.color_selbrushes[2] * .65f);
1896 StringOutputStream dimensions(16);
1898 if (m_viewType == XY)
1902 glVertex3f(vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f);
1903 glVertex3f(vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f);
1905 glVertex3f(vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f);
1906 glVertex3f(vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f);
1908 glVertex3f(vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f);
1909 glVertex3f(vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f);
1912 glVertex3f(vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2], 0.0f);
1913 glVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f);
1915 glVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f);
1916 glVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f);
1918 glVertex3f(vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2], 0.0f);
1919 glVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f);
1923 glRasterPos3f (Betwixt(vMinBounds[nDim1], vMaxBounds[nDim1]), vMinBounds[nDim2] - 20.0f / m_fScale, 0.0f);
1924 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
1925 GlobalOpenGL().drawString(dimensions.c_str());
1928 glRasterPos3f (vMaxBounds[nDim1] + 16.0f / m_fScale, Betwixt(vMinBounds[nDim2], vMaxBounds[nDim2]), 0.0f);
1929 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
1930 GlobalOpenGL().drawString(dimensions.c_str());
1933 glRasterPos3f (vMinBounds[nDim1] + 4, vMaxBounds[nDim2] + 8 / m_fScale, 0.0f);
1934 dimensions << "(" << g_pOrgStrings[0][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[0][1] << vMaxBounds[nDim2] << ")";
1935 GlobalOpenGL().drawString(dimensions.c_str());
1937 else if (m_viewType == XZ)
1941 glVertex3f(vMinBounds[nDim1], 0, vMinBounds[nDim2] - 6.0f / m_fScale);
1942 glVertex3f(vMinBounds[nDim1], 0, vMinBounds[nDim2] - 10.0f / m_fScale);
1944 glVertex3f(vMinBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale);
1945 glVertex3f(vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale);
1947 glVertex3f(vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 6.0f / m_fScale);
1948 glVertex3f(vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale);
1951 glVertex3f(vMaxBounds[nDim1] + 6.0f / m_fScale, 0,vMinBounds[nDim2]);
1952 glVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMinBounds[nDim2]);
1954 glVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMinBounds[nDim2]);
1955 glVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMaxBounds[nDim2]);
1957 glVertex3f(vMaxBounds[nDim1] + 6.0f / m_fScale, 0,vMaxBounds[nDim2]);
1958 glVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMaxBounds[nDim2]);
1962 glRasterPos3f (Betwixt(vMinBounds[nDim1], vMaxBounds[nDim1]), 0, vMinBounds[nDim2] - 20.0f / m_fScale);
1963 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
1964 GlobalOpenGL().drawString(dimensions.c_str());
1967 glRasterPos3f (vMaxBounds[nDim1] + 16.0f / m_fScale, 0, Betwixt(vMinBounds[nDim2], vMaxBounds[nDim2]));
1968 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
1969 GlobalOpenGL().drawString(dimensions.c_str());
1972 glRasterPos3f (vMinBounds[nDim1] + 4, 0, vMaxBounds[nDim2] + 8 / m_fScale);
1973 dimensions << "(" << g_pOrgStrings[1][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[1][1] << vMaxBounds[nDim2] << ")";
1974 GlobalOpenGL().drawString(dimensions.c_str());
1980 glVertex3f(0, vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale);
1981 glVertex3f(0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale);
1983 glVertex3f(0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale);
1984 glVertex3f(0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale);
1986 glVertex3f(0, vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale);
1987 glVertex3f(0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale);
1990 glVertex3f(0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2]);
1991 glVertex3f(0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2]);
1993 glVertex3f(0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2]);
1994 glVertex3f(0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2]);
1996 glVertex3f(0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2]);
1997 glVertex3f(0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2]);
2001 glRasterPos3f (0, Betwixt(vMinBounds[nDim1], vMaxBounds[nDim1]), vMinBounds[nDim2] - 20.0f / m_fScale);
2002 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
2003 GlobalOpenGL().drawString(dimensions.c_str());
2006 glRasterPos3f (0, vMaxBounds[nDim1] + 16.0f / m_fScale, Betwixt(vMinBounds[nDim2], vMaxBounds[nDim2]));
2007 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
2008 GlobalOpenGL().drawString(dimensions.c_str());
2011 glRasterPos3f (0, vMinBounds[nDim1] + 4.0f, vMaxBounds[nDim2] + 8 / m_fScale);
2012 dimensions << "(" << g_pOrgStrings[2][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[2][1] << vMaxBounds[nDim2] << ")";
2013 GlobalOpenGL().drawString(dimensions.c_str());
2017 class XYRenderer: public Renderer
2026 unsigned int m_highlight;
2030 XYRenderer(RenderStateFlags globalstate, Shader* selected) :
2031 m_globalstate(globalstate),
2032 m_state_selected(selected)
2034 ASSERT_NOTNULL(selected);
2035 m_state_stack.push_back(state_type());
2038 void SetState(Shader* state, EStyle style)
2040 ASSERT_NOTNULL(state);
2041 if(style == eWireframeOnly)
2042 m_state_stack.back().m_state = state;
2044 const EStyle getStyle() const
2046 return eWireframeOnly;
2050 m_state_stack.push_back(m_state_stack.back());
2054 ASSERT_MESSAGE(!m_state_stack.empty(), "popping empty stack");
2055 m_state_stack.pop_back();
2057 void Highlight(EHighlightMode mode, bool bEnable = true)
2060 ? m_state_stack.back().m_highlight |= mode
2061 : m_state_stack.back().m_highlight &= ~mode;
2063 void addRenderable(const OpenGLRenderable& renderable, const Matrix4& localToWorld)
2065 if(m_state_stack.back().m_highlight & ePrimitive)
2067 m_state_selected->addRenderable(renderable, localToWorld);
2071 m_state_stack.back().m_state->addRenderable(renderable, localToWorld);
2075 void render(const Matrix4& modelview, const Matrix4& projection)
2077 GlobalShaderCache().render(m_globalstate, modelview, projection);
2080 std::vector<state_type> m_state_stack;
2081 RenderStateFlags m_globalstate;
2082 Shader* m_state_selected;
2085 void XYWnd::updateProjection()
2087 m_projection[0] = 1.0f / static_cast<float>(m_nWidth / 2);
2088 m_projection[5] = 1.0f / static_cast<float>(m_nHeight / 2);
2089 m_projection[10] = 1.0f / g_MaxWorldCoord;
2091 m_projection[12] = 0.0f;
2092 m_projection[13] = 0.0f;
2093 m_projection[14] = -1.0f;
2105 m_projection[11] = 0.0f;
2107 m_projection[15] = 1.0f;
2109 m_view.Construct(m_projection, m_modelview, m_nWidth, m_nHeight);
2112 void XYWnd::updateModelview()
2114 int nDim1 = (m_viewType == YZ) ? 1 : 0;
2115 int nDim2 = (m_viewType == XY) ? 1 : 2;
2118 m_modelview[12] = -m_vOrigin[nDim1] * m_fScale;
2119 m_modelview[13] = -m_vOrigin[nDim2] * m_fScale;
2120 m_modelview[14] = static_cast<float>(g_MaxWorldCoord);
2126 m_modelview[0] = m_fScale;
2131 m_modelview[5] = m_fScale;
2136 m_modelview[10] = -m_fScale;
2139 m_modelview[0] = m_fScale;
2145 m_modelview[6] = m_fScale;
2148 m_modelview[9] = m_fScale;
2149 m_modelview[10] = 0;
2154 m_modelview[2] = -m_fScale;
2156 m_modelview[4] = m_fScale;
2161 m_modelview[9] = m_fScale;
2162 m_modelview[10] = 0;
2166 m_modelview[3] = m_modelview[7] = m_modelview[11] = 0;
2167 m_modelview[15] = 1;
2169 m_view.Construct(m_projection, m_modelview, m_nWidth, m_nHeight);
2178 //#define DBG_SCENEDUMP
2180 void XYWnd::XY_Draw()
2185 glViewport(0, 0, m_nWidth, m_nHeight);
2186 glClearColor (g_xywindow_globals.color_gridback[0],
2187 g_xywindow_globals.color_gridback[1],
2188 g_xywindow_globals.color_gridback[2],0);
2190 glClear(GL_COLOR_BUFFER_BIT);
2196 glMatrixMode(GL_PROJECTION);
2197 glLoadMatrixf(reinterpret_cast<const float*>(&m_projection));
2199 glMatrixMode(GL_MODELVIEW);
2201 glScalef(m_fScale, m_fScale, 1);
2202 int nDim1 = (m_viewType == YZ) ? 1 : 0;
2203 int nDim2 = (m_viewType == XY) ? 1 : 2;
2204 glTranslatef(-m_vOrigin[nDim1], -m_vOrigin[nDim2], 0);
2206 glDisable (GL_LINE_STIPPLE);
2208 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
2209 glDisableClientState(GL_NORMAL_ARRAY);
2210 glDisableClientState(GL_COLOR_ARRAY);
2211 glDisable(GL_TEXTURE_2D);
2212 glDisable(GL_LIGHTING);
2213 glDisable(GL_COLOR_MATERIAL);
2214 glDisable(GL_DEPTH_TEST);
2217 if ( g_xywindow_globals_private.show_blocks)
2220 glLoadMatrixf(reinterpret_cast<const float*>(&m_modelview));
2222 unsigned int globalstate = RENDER_COLOUR | RENDER_COLOURWRITE;
2223 if(!g_xywindow_globals.m_bNoStipple)
2225 globalstate |= RENDER_LINESTIPPLE;
2229 XYRenderer renderer(globalstate, m_state_selected);
2231 Scene_Render(renderer, m_view);
2233 GlobalOpenGL_debugAssertNoErrors();
2234 renderer.render(m_modelview, m_projection);
2235 GlobalOpenGL_debugAssertNoErrors();
2238 glDepthMask(GL_FALSE);
2240 GlobalOpenGL_debugAssertNoErrors();
2242 glLoadMatrixf(reinterpret_cast<const float*>(&m_modelview));
2244 GlobalOpenGL_debugAssertNoErrors();
2245 glDisable(GL_LINE_STIPPLE);
2246 GlobalOpenGL_debugAssertNoErrors();
2248 GlobalOpenGL_debugAssertNoErrors();
2249 if(GlobalOpenGL().GL_1_3())
2251 glActiveTexture(GL_TEXTURE0);
2252 glClientActiveTexture(GL_TEXTURE0);
2254 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
2255 GlobalOpenGL_debugAssertNoErrors();
2256 glDisableClientState(GL_NORMAL_ARRAY);
2257 GlobalOpenGL_debugAssertNoErrors();
2258 glDisableClientState(GL_COLOR_ARRAY);
2259 GlobalOpenGL_debugAssertNoErrors();
2260 glDisable(GL_TEXTURE_2D);
2261 GlobalOpenGL_debugAssertNoErrors();
2262 glDisable(GL_LIGHTING);
2263 GlobalOpenGL_debugAssertNoErrors();
2264 glDisable(GL_COLOR_MATERIAL);
2265 GlobalOpenGL_debugAssertNoErrors();
2267 GlobalOpenGL_debugAssertNoErrors();
2271 if(g_xywindow_globals_private.m_bSizePaint && GlobalSelectionSystem().countSelected() != 0)
2274 Select_GetBounds(min, max);
2275 PaintSizeInfo(nDim1, nDim2, min, max);
2280 glColor4f(0.2f, 0.9f, 0.2f, 0.8f);
2282 if (m_viewType == XY)
2284 glVertex2f(2.0f * g_MinWorldCoord, m_mousePosition[1]);
2285 glVertex2f(2.0f * g_MaxWorldCoord, m_mousePosition[1]);
2286 glVertex2f(m_mousePosition[0], 2.0f * g_MinWorldCoord);
2287 glVertex2f(m_mousePosition[0], 2.0f * g_MaxWorldCoord);
2289 else if (m_viewType == YZ)
2291 glVertex3f(m_mousePosition[0], 2.0f * g_MinWorldCoord, m_mousePosition[2]);
2292 glVertex3f(m_mousePosition[0], 2.0f * g_MaxWorldCoord, m_mousePosition[2]);
2293 glVertex3f(m_mousePosition[0], m_mousePosition[1], 2.0f * g_MinWorldCoord);
2294 glVertex3f(m_mousePosition[0], m_mousePosition[1], 2.0f * g_MaxWorldCoord);
2298 glVertex3f (2.0f * g_MinWorldCoord, m_mousePosition[1], m_mousePosition[2]);
2299 glVertex3f (2.0f * g_MaxWorldCoord, m_mousePosition[1], m_mousePosition[2]);
2300 glVertex3f(m_mousePosition[0], m_mousePosition[1], 2.0f * g_MinWorldCoord);
2301 glVertex3f(m_mousePosition[0], m_mousePosition[1], 2.0f * g_MaxWorldCoord);
2308 GlobalClipPoints_Draw(m_fScale);
2311 GlobalOpenGL_debugAssertNoErrors();
2315 glScalef(m_fScale, m_fScale, 1);
2316 glTranslatef(-m_vOrigin[nDim1], -m_vOrigin[nDim2], 0);
2318 DrawCameraIcon (Camera_getOrigin(*g_pParentWnd->GetCamWnd()), Camera_getAngles(*g_pParentWnd->GetCamWnd()));
2320 Feedback_draw2D( m_viewType );
2322 if (g_xywindow_globals_private.show_outline)
2326 glMatrixMode (GL_PROJECTION);
2328 glOrtho (0, m_nWidth, 0, m_nHeight, 0, 1);
2330 glMatrixMode (GL_MODELVIEW);
2333 // four view mode doesn't colorize
2334 if (g_pParentWnd->CurrentStyle() == MainFrame::eSplit)
2335 glColor3fv(vector3_to_array(g_xywindow_globals.color_viewname));
2341 glColor3fv(vector3_to_array(g_xywindow_globals.AxisColorX));
2344 glColor3fv(vector3_to_array(g_xywindow_globals.AxisColorY));
2347 glColor3fv(vector3_to_array(g_xywindow_globals.AxisColorZ));
2351 glBegin (GL_LINE_LOOP);
2353 glVertex2i (m_nWidth-1, 0);
2354 glVertex2i (m_nWidth-1, m_nHeight-1);
2355 glVertex2i (0, m_nHeight-1);
2360 GlobalOpenGL_debugAssertNoErrors();
2365 void XYWnd_MouseToPoint(XYWnd* xywnd, int x, int y, Vector3& point)
2367 xywnd->XY_ToPoint(x, y, point);
2368 xywnd->XY_SnapToGrid(point);
2370 int nDim = (xywnd->GetViewType() == XY) ? 2 : (xywnd->GetViewType() == YZ) ? 0 : 1;
2371 float fWorkMid = float_mid(Select_getWorkZone().d_work_min[nDim], Select_getWorkZone().d_work_max[nDim]);
2372 point[nDim] = float_snapped(fWorkMid, GetGridSize());
2375 void XYWnd::OnEntityCreate (const char* item)
2377 StringOutputStream command;
2378 command << "entityCreate -class " << item;
2379 UndoableCommand undo(command.c_str());
2381 XYWnd_MouseToPoint(this, m_entityCreate_x, m_entityCreate_y, point);
2382 Entity_createFromSelection(item, point);
2387 void GetFocusPosition(Vector3& position)
2389 if(GlobalSelectionSystem().countSelected() != 0)
2391 Select_GetMid(position);
2395 position = Camera_getOrigin(*g_pParentWnd->GetCamWnd());
2399 void XYWnd_Focus(XYWnd* xywnd)
2402 GetFocusPosition(position);
2403 xywnd->PositionView(position);
2406 void XY_Split_Focus()
2409 GetFocusPosition(position);
2410 g_pParentWnd->GetXYWnd()->PositionView(position);
2411 g_pParentWnd->GetXZWnd()->PositionView(position);
2412 g_pParentWnd->GetYZWnd()->PositionView(position);
2417 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2423 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2424 xywnd->SetViewType(XY);
2430 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2431 xywnd->SetViewType(XZ);
2437 g_pParentWnd->GetXYWnd()->SetViewType(YZ);
2438 XYWnd_Focus(g_pParentWnd->GetXYWnd());
2443 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2444 if (xywnd->GetViewType() == XY)
2445 xywnd->SetViewType(XZ);
2446 else if (xywnd->GetViewType() == XZ)
2447 xywnd->SetViewType(YZ);
2449 xywnd->SetViewType(XY);
2455 if (g_pParentWnd->GetXYWnd())
2456 g_pParentWnd->GetXYWnd()->SetScale(1);
2457 if (g_pParentWnd->GetXZWnd())
2458 g_pParentWnd->GetXZWnd()->SetScale(1);
2459 if (g_pParentWnd->GetYZWnd())
2460 g_pParentWnd->GetYZWnd()->SetScale(1);
2465 XYWnd_ZoomIn(g_pParentWnd->ActiveXY());
2468 // NOTE: the zoom out factor is 4/5, we could think about customizing it
2469 // we don't go below a zoom factor corresponding to 10% of the max world size
2470 // (this has to be computed against the window size)
2473 XYWnd_ZoomOut(g_pParentWnd->ActiveXY());
2478 void ToggleShowCrosshair()
2481 XY_UpdateAllWindows();
2484 void ToggleShowSizeInfo()
2486 g_xywindow_globals_private.m_bSizePaint = !g_xywindow_globals_private.m_bSizePaint;
2487 XY_UpdateAllWindows();
2490 void ToggleShowGrid()
2492 g_xywindow_globals_private.d_showgrid = !g_xywindow_globals_private.d_showgrid;
2493 XY_UpdateAllWindows();
2496 ToggleShown g_xy_top_shown(true);
2498 void XY_Top_Shown_Construct(GtkWindow* parent)
2500 g_xy_top_shown.connect(GTK_WIDGET(parent));
2503 ToggleShown g_yz_side_shown(false);
2505 void YZ_Side_Shown_Construct(GtkWindow* parent)
2507 g_yz_side_shown.connect(GTK_WIDGET(parent));
2510 ToggleShown g_xz_front_shown(false);
2512 void XZ_Front_Shown_Construct(GtkWindow* parent)
2514 g_xz_front_shown.connect(GTK_WIDGET(parent));
2518 class EntityClassMenu : public ModuleObserver
2520 std::size_t m_unrealised;
2522 EntityClassMenu() : m_unrealised(1)
2527 if(--m_unrealised == 0)
2533 if(++m_unrealised == 1)
2535 if(XYWnd::m_mnuDrop != 0)
2537 gtk_widget_destroy(GTK_WIDGET(XYWnd::m_mnuDrop));
2538 XYWnd::m_mnuDrop = 0;
2544 EntityClassMenu g_EntityClassMenu;
2549 void ShowNamesToggle()
2551 GlobalEntityCreator().setShowNames(!GlobalEntityCreator().getShowNames());
2552 XY_UpdateAllWindows();
2554 typedef FreeCaller<ShowNamesToggle> ShowNamesToggleCaller;
2555 void ShowNamesExport(const BoolImportCallback& importer)
2557 importer(GlobalEntityCreator().getShowNames());
2559 typedef FreeCaller1<const BoolImportCallback&, ShowNamesExport> ShowNamesExportCaller;
2561 void ShowAnglesToggle()
2563 GlobalEntityCreator().setShowAngles(!GlobalEntityCreator().getShowAngles());
2564 XY_UpdateAllWindows();
2566 typedef FreeCaller<ShowAnglesToggle> ShowAnglesToggleCaller;
2567 void ShowAnglesExport(const BoolImportCallback& importer)
2569 importer(GlobalEntityCreator().getShowAngles());
2571 typedef FreeCaller1<const BoolImportCallback&, ShowAnglesExport> ShowAnglesExportCaller;
2573 void ShowBlocksToggle()
2575 g_xywindow_globals_private.show_blocks ^= 1;
2576 XY_UpdateAllWindows();
2578 typedef FreeCaller<ShowBlocksToggle> ShowBlocksToggleCaller;
2579 void ShowBlocksExport(const BoolImportCallback& importer)
2581 importer(g_xywindow_globals_private.show_blocks);
2583 typedef FreeCaller1<const BoolImportCallback&, ShowBlocksExport> ShowBlocksExportCaller;
2585 void ShowCoordinatesToggle()
2587 g_xywindow_globals_private.show_coordinates ^= 1;
2588 XY_UpdateAllWindows();
2590 typedef FreeCaller<ShowCoordinatesToggle> ShowCoordinatesToggleCaller;
2591 void ShowCoordinatesExport(const BoolImportCallback& importer)
2593 importer(g_xywindow_globals_private.show_coordinates);
2595 typedef FreeCaller1<const BoolImportCallback&, ShowCoordinatesExport> ShowCoordinatesExportCaller;
2597 void ShowOutlineToggle()
2599 g_xywindow_globals_private.show_outline ^= 1;
2600 XY_UpdateAllWindows();
2602 typedef FreeCaller<ShowOutlineToggle> ShowOutlineToggleCaller;
2603 void ShowOutlineExport(const BoolImportCallback& importer)
2605 importer(g_xywindow_globals_private.show_outline);
2607 typedef FreeCaller1<const BoolImportCallback&, ShowOutlineExport> ShowOutlineExportCaller;
2609 void ShowAxesToggle()
2611 g_xywindow_globals_private.show_axis ^= 1;
2612 XY_UpdateAllWindows();
2614 typedef FreeCaller<ShowAxesToggle> ShowAxesToggleCaller;
2615 void ShowAxesExport(const BoolImportCallback& importer)
2617 importer(g_xywindow_globals_private.show_axis);
2619 typedef FreeCaller1<const BoolImportCallback&, ShowAxesExport> ShowAxesExportCaller;
2621 void ShowWorkzoneToggle()
2623 g_xywindow_globals_private.d_show_work ^= 1;
2624 XY_UpdateAllWindows();
2626 typedef FreeCaller<ShowWorkzoneToggle> ShowWorkzoneToggleCaller;
2627 void ShowWorkzoneExport(const BoolImportCallback& importer)
2629 importer(g_xywindow_globals_private.d_show_work);
2631 typedef FreeCaller1<const BoolImportCallback&, ShowWorkzoneExport> ShowWorkzoneExportCaller;
2633 ShowNamesExportCaller g_show_names_caller;
2634 BoolExportCallback g_show_names_callback(g_show_names_caller);
2635 ToggleItem g_show_names(g_show_names_callback);
2637 ShowAnglesExportCaller g_show_angles_caller;
2638 BoolExportCallback g_show_angles_callback(g_show_angles_caller);
2639 ToggleItem g_show_angles(g_show_angles_callback);
2641 ShowBlocksExportCaller g_show_blocks_caller;
2642 BoolExportCallback g_show_blocks_callback(g_show_blocks_caller);
2643 ToggleItem g_show_blocks(g_show_blocks_callback);
2645 ShowCoordinatesExportCaller g_show_coordinates_caller;
2646 BoolExportCallback g_show_coordinates_callback(g_show_coordinates_caller);
2647 ToggleItem g_show_coordinates(g_show_coordinates_callback);
2649 ShowOutlineExportCaller g_show_outline_caller;
2650 BoolExportCallback g_show_outline_callback(g_show_outline_caller);
2651 ToggleItem g_show_outline(g_show_outline_callback);
2653 ShowAxesExportCaller g_show_axes_caller;
2654 BoolExportCallback g_show_axes_callback(g_show_axes_caller);
2655 ToggleItem g_show_axes(g_show_axes_callback);
2657 ShowWorkzoneExportCaller g_show_workzone_caller;
2658 BoolExportCallback g_show_workzone_callback(g_show_workzone_caller);
2659 ToggleItem g_show_workzone(g_show_workzone_callback);
2661 void XYShow_registerCommands()
2663 GlobalToggles_insert("ShowAngles", ShowAnglesToggleCaller(), ToggleItem::AddCallbackCaller(g_show_angles));
2664 GlobalToggles_insert("ShowNames", ShowNamesToggleCaller(), ToggleItem::AddCallbackCaller(g_show_names));
2665 GlobalToggles_insert("ShowBlocks", ShowBlocksToggleCaller(), ToggleItem::AddCallbackCaller(g_show_blocks));
2666 GlobalToggles_insert("ShowCoordinates", ShowCoordinatesToggleCaller(), ToggleItem::AddCallbackCaller(g_show_coordinates));
2667 GlobalToggles_insert("ShowWindowOutline", ShowOutlineToggleCaller(), ToggleItem::AddCallbackCaller(g_show_outline));
2668 GlobalToggles_insert("ShowAxes", ShowAxesToggleCaller(), ToggleItem::AddCallbackCaller(g_show_axes));
2669 GlobalToggles_insert("ShowWorkzone", ShowWorkzoneToggleCaller(), ToggleItem::AddCallbackCaller(g_show_workzone));
2672 void XYWnd_registerShortcuts()
2674 command_connect_accelerator("ToggleCrosshairs");
2675 command_connect_accelerator("ToggleSizePaint");
2680 void Orthographic_constructPreferences(PreferencesPage& page)
2682 page.appendCheckBox("", "Solid selection boxes", g_xywindow_globals.m_bNoStipple);
2683 page.appendCheckBox("", "Display size info", g_xywindow_globals_private.m_bSizePaint);
2684 page.appendCheckBox("", "Chase mouse during drags", g_xywindow_globals_private.m_bChaseMouse);
2685 page.appendCheckBox("", "Update views on camera move", g_xywindow_globals_private.m_bCamXYUpdate);
2687 void Orthographic_constructPage(PreferenceGroup& group)
2689 PreferencesPage page(group.createPage("Orthographic", "Orthographic View Preferences"));
2690 Orthographic_constructPreferences(page);
2692 void Orthographic_registerPreferencesPage()
2694 PreferencesDialog_addSettingsPage(FreeCaller1<PreferenceGroup&, Orthographic_constructPage>());
2697 void Clipper_constructPreferences(PreferencesPage& page)
2699 page.appendCheckBox("", "Clipper tool uses caulk", g_clip_useCaulk);
2701 void Clipper_constructPage(PreferenceGroup& group)
2703 PreferencesPage page(group.createPage("Clipper", "Clipper Tool Settings"));
2704 Clipper_constructPreferences(page);
2706 void Clipper_registerPreferencesPage()
2708 PreferencesDialog_addSettingsPage(FreeCaller1<PreferenceGroup&, Clipper_constructPage>());
2712 #include "preferencesystem.h"
2713 #include "stringio.h"
2718 void ToggleShown_importBool(ToggleShown& self, bool value)
2722 typedef ReferenceCaller1<ToggleShown, bool, ToggleShown_importBool> ToggleShownImportBoolCaller;
2723 void ToggleShown_exportBool(const ToggleShown& self, const BoolImportCallback& importer)
2725 importer(self.active());
2727 typedef ConstReferenceCaller1<ToggleShown, const BoolImportCallback&, ToggleShown_exportBool> ToggleShownExportBoolCaller;
2730 void XYWindow_Construct()
2732 GlobalCommands_insert("ToggleCrosshairs", FreeCaller<ToggleShowCrosshair>(), Accelerator('X', (GdkModifierType)GDK_SHIFT_MASK));
2733 GlobalCommands_insert("ToggleSizePaint", FreeCaller<ToggleShowSizeInfo>(), Accelerator('J'));
2734 GlobalCommands_insert("ToggleGrid", FreeCaller<ToggleShowGrid>(), Accelerator('0'));
2736 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)));
2737 GlobalToggles_insert("ToggleSideView", ToggleShown::ToggleCaller(g_yz_side_shown), ToggleItem::AddCallbackCaller(g_yz_side_shown.m_item));
2738 GlobalToggles_insert("ToggleFrontView", ToggleShown::ToggleCaller(g_xz_front_shown), ToggleItem::AddCallbackCaller(g_xz_front_shown.m_item));
2739 GlobalCommands_insert("NextView", FreeCaller<XY_Next>(), Accelerator(GDK_Tab, (GdkModifierType)GDK_CONTROL_MASK));
2740 GlobalCommands_insert("ZoomIn", FreeCaller<XY_ZoomIn>(), Accelerator(GDK_Delete));
2741 GlobalCommands_insert("ZoomOut", FreeCaller<XY_ZoomOut>(), Accelerator(GDK_Insert));
2742 GlobalCommands_insert("ViewTop", FreeCaller<XY_Top>());
2743 GlobalCommands_insert("ViewSide", FreeCaller<XY_Side>());
2744 GlobalCommands_insert("ViewFront", FreeCaller<XY_Front>());
2745 GlobalCommands_insert("Zoom100", FreeCaller<XY_Zoom100>());
2746 GlobalCommands_insert("CenterXYViews", FreeCaller<XY_Split_Focus>(), Accelerator(GDK_Tab, (GdkModifierType)(GDK_SHIFT_MASK|GDK_CONTROL_MASK)));
2747 GlobalCommands_insert("CenterXYView", FreeCaller<XY_Focus>(), Accelerator(GDK_Tab, (GdkModifierType)(GDK_SHIFT_MASK|GDK_CONTROL_MASK)));
2749 GlobalPreferenceSystem().registerPreference("ClipCaulk", BoolImportStringCaller(g_clip_useCaulk), BoolExportStringCaller(g_clip_useCaulk));
2751 GlobalPreferenceSystem().registerPreference("NewRightClick", BoolImportStringCaller(g_xywindow_globals.m_bRightClick), BoolExportStringCaller(g_xywindow_globals.m_bRightClick));
2752 GlobalPreferenceSystem().registerPreference("ChaseMouse", BoolImportStringCaller(g_xywindow_globals_private.m_bChaseMouse), BoolExportStringCaller(g_xywindow_globals_private.m_bChaseMouse));
2753 GlobalPreferenceSystem().registerPreference("SizePainting", BoolImportStringCaller(g_xywindow_globals_private.m_bSizePaint), BoolExportStringCaller(g_xywindow_globals_private.m_bSizePaint));
2754 GlobalPreferenceSystem().registerPreference("NoStipple", BoolImportStringCaller(g_xywindow_globals.m_bNoStipple), BoolExportStringCaller(g_xywindow_globals.m_bNoStipple));
2755 GlobalPreferenceSystem().registerPreference("SI_ShowCoords", BoolImportStringCaller(g_xywindow_globals_private.show_coordinates), BoolExportStringCaller(g_xywindow_globals_private.show_coordinates));
2756 GlobalPreferenceSystem().registerPreference("SI_ShowOutlines", BoolImportStringCaller(g_xywindow_globals_private.show_outline), BoolExportStringCaller(g_xywindow_globals_private.show_outline));
2757 GlobalPreferenceSystem().registerPreference("SI_ShowAxis", BoolImportStringCaller(g_xywindow_globals_private.show_axis), BoolExportStringCaller(g_xywindow_globals_private.show_axis));
2758 GlobalPreferenceSystem().registerPreference("CamXYUpdate", BoolImportStringCaller(g_xywindow_globals_private.m_bCamXYUpdate), BoolExportStringCaller(g_xywindow_globals_private.m_bCamXYUpdate));
2760 GlobalPreferenceSystem().registerPreference("SI_AxisColors0", Vector3ImportStringCaller(g_xywindow_globals.AxisColorX), Vector3ExportStringCaller(g_xywindow_globals.AxisColorX));
2761 GlobalPreferenceSystem().registerPreference("SI_AxisColors1", Vector3ImportStringCaller(g_xywindow_globals.AxisColorY), Vector3ExportStringCaller(g_xywindow_globals.AxisColorY));
2762 GlobalPreferenceSystem().registerPreference("SI_AxisColors2", Vector3ImportStringCaller(g_xywindow_globals.AxisColorZ), Vector3ExportStringCaller(g_xywindow_globals.AxisColorZ));
2763 GlobalPreferenceSystem().registerPreference("SI_Colors1", Vector3ImportStringCaller(g_xywindow_globals.color_gridback), Vector3ExportStringCaller(g_xywindow_globals.color_gridback));
2764 GlobalPreferenceSystem().registerPreference("SI_Colors2", Vector3ImportStringCaller(g_xywindow_globals.color_gridminor), Vector3ExportStringCaller(g_xywindow_globals.color_gridminor));
2765 GlobalPreferenceSystem().registerPreference("SI_Colors3", Vector3ImportStringCaller(g_xywindow_globals.color_gridmajor), Vector3ExportStringCaller(g_xywindow_globals.color_gridmajor));
2766 GlobalPreferenceSystem().registerPreference("SI_Colors6", Vector3ImportStringCaller(g_xywindow_globals.color_gridblock), Vector3ExportStringCaller(g_xywindow_globals.color_gridblock));
2767 GlobalPreferenceSystem().registerPreference("SI_Colors7", Vector3ImportStringCaller(g_xywindow_globals.color_gridtext), Vector3ExportStringCaller(g_xywindow_globals.color_gridtext));
2768 GlobalPreferenceSystem().registerPreference("SI_Colors8", Vector3ImportStringCaller(g_xywindow_globals.color_brushes), Vector3ExportStringCaller(g_xywindow_globals.color_brushes));
2769 GlobalPreferenceSystem().registerPreference("SI_Colors9", Vector3ImportStringCaller(g_xywindow_globals.color_selbrushes), Vector3ExportStringCaller(g_xywindow_globals.color_selbrushes));
2770 GlobalPreferenceSystem().registerPreference("SI_Colors10", Vector3ImportStringCaller(g_xywindow_globals.color_clipper), Vector3ExportStringCaller(g_xywindow_globals.color_clipper));
2771 GlobalPreferenceSystem().registerPreference("SI_Colors11", Vector3ImportStringCaller(g_xywindow_globals.color_viewname), Vector3ExportStringCaller(g_xywindow_globals.color_viewname));
2772 GlobalPreferenceSystem().registerPreference("SI_Colors13", Vector3ImportStringCaller(g_xywindow_globals.color_gridminor_alt), Vector3ExportStringCaller(g_xywindow_globals.color_gridminor_alt));
2773 GlobalPreferenceSystem().registerPreference("SI_Colors14", Vector3ImportStringCaller(g_xywindow_globals.color_gridmajor_alt), Vector3ExportStringCaller(g_xywindow_globals.color_gridmajor_alt));
2776 GlobalPreferenceSystem().registerPreference("XZVIS", makeBoolStringImportCallback(ToggleShownImportBoolCaller(g_xz_front_shown)), makeBoolStringExportCallback(ToggleShownExportBoolCaller(g_xz_front_shown)));
2777 GlobalPreferenceSystem().registerPreference("YZVIS", makeBoolStringImportCallback(ToggleShownImportBoolCaller(g_yz_side_shown)), makeBoolStringExportCallback(ToggleShownExportBoolCaller(g_yz_side_shown)));
2779 Orthographic_registerPreferencesPage();
2780 Clipper_registerPreferencesPage();
2782 XYWnd::captureStates();
2783 GlobalEntityClassManager().attach(g_EntityClassMenu);
2786 void XYWindow_Destroy()
2788 GlobalEntityClassManager().detach(g_EntityClassMenu);
2789 XYWnd::releaseStates();