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"
45 #include "eclasslib.h"
47 #include "moduleobserver.h"
49 #include "gtkutil/menu.h"
50 #include "gtkutil/container.h"
51 #include "gtkutil/widget.h"
52 #include "gtkutil/glwidget.h"
56 #include "brushmanip.h"
57 #include "selection.h"
59 #include "camwindow.h"
60 #include "texwindow.h"
61 #include "mainframe.h"
62 #include "preferences.h"
66 #include "windowobservers.h"
75 Vector3 m_ptClip; // the 3d point
84 m_ptClip[0] = m_ptClip[1] = m_ptClip[2] = 0.0;
100 /*! Draw clip/path point with rasterized number label */
101 void Draw(int num, float scale);
102 /*! Draw clip/path point with rasterized string label */
103 void Draw(const char *label, float scale);
106 VIEWTYPE g_clip_viewtype;
107 bool g_bSwitch = true;
108 bool g_clip_useCaulk = false;
112 ClipPoint* g_pMovingClip = 0;
114 /* Drawing clip points */
115 void ClipPoint::Draw(int num, float scale)
117 StringOutputStream label(4);
119 Draw(label.c_str(), scale);
122 void ClipPoint::Draw(const char *label, float scale)
126 glColor3fv(vector3_to_array(g_xywindow_globals.color_clipper));
128 glVertex3fv(vector3_to_array(m_ptClip));
132 float offset = 2.0f / scale;
135 glRasterPos3f (m_ptClip[0] + offset, m_ptClip[1] + offset, m_ptClip[2] + offset);
136 glCallLists (GLsizei(strlen(label)), GL_UNSIGNED_BYTE, label);
139 float fDiff(float f1, float f2)
147 inline double ClipPoint_Intersect(const ClipPoint& clip, const Vector3& point, VIEWTYPE viewtype, float scale)
149 int nDim1 = (viewtype == YZ) ? 1 : 0;
150 int nDim2 = (viewtype == XY) ? 1 : 2;
151 double screenDistanceSquared(vector2_length_squared(Vector2(fDiff(clip.m_ptClip[nDim1], point[nDim1]) * scale, fDiff(clip.m_ptClip[nDim2], point[nDim2]) * scale)));
152 if(screenDistanceSquared < 8*8)
154 return screenDistanceSquared;
159 inline void ClipPoint_testSelect(ClipPoint& clip, const Vector3& point, VIEWTYPE viewtype, float scale, double& bestDistance, ClipPoint*& bestClip)
163 double distance = ClipPoint_Intersect(clip, point, viewtype, scale);
164 if(distance < bestDistance)
166 bestDistance = distance;
172 inline ClipPoint* GlobalClipPoints_Find(const Vector3& point, VIEWTYPE viewtype, float scale)
174 double bestDistance = FLT_MAX;
175 ClipPoint* bestClip = 0;
176 ClipPoint_testSelect(g_Clip1, point, viewtype, scale, bestDistance, bestClip);
177 ClipPoint_testSelect(g_Clip2, point, viewtype, scale, bestDistance, bestClip);
178 ClipPoint_testSelect(g_Clip3, point, viewtype, scale, bestDistance, bestClip);
182 inline void GlobalClipPoints_Draw(float scale)
186 g_Clip1.Draw(1, scale);
188 g_Clip2.Draw(2, scale);
190 g_Clip3.Draw(3, scale);
193 inline bool GlobalClipPoints_valid()
195 return g_Clip1.Set() && g_Clip2.Set();
198 void PlanePointsFromClipPoints(Vector3 planepts[3], const AABB& bounds, int viewtype)
200 ASSERT_MESSAGE(GlobalClipPoints_valid(), "clipper points not initialised");
201 planepts[0] = g_Clip1.m_ptClip;
202 planepts[1] = g_Clip2.m_ptClip;
203 planepts[2] = g_Clip3.m_ptClip;
204 Vector3 maxs(vector3_added(bounds.origin, bounds.extents));
205 Vector3 mins(vector3_subtracted(bounds.origin, bounds.extents));
208 int n = (viewtype == XY) ? 2 : (viewtype == YZ) ? 0 : 1;
209 int x = (n == 0) ? 1 : 0;
210 int y = (n == 2) ? 1 : 2;
212 if (n == 1) // on viewtype XZ, flip clip points
214 planepts[0][n] = maxs[n];
215 planepts[1][n] = maxs[n];
216 planepts[2][x] = g_Clip1.m_ptClip[x];
217 planepts[2][y] = g_Clip1.m_ptClip[y];
218 planepts[2][n] = mins[n];
222 planepts[0][n] = mins[n];
223 planepts[1][n] = mins[n];
224 planepts[2][x] = g_Clip1.m_ptClip[x];
225 planepts[2][y] = g_Clip1.m_ptClip[y];
226 planepts[2][n] = maxs[n];
234 if(!GlobalClipPoints_valid())
236 planepts[0] = Vector3(0, 0, 0);
237 planepts[1] = Vector3(0, 0, 0);
238 planepts[2] = Vector3(0, 0, 0);
239 Scene_BrushSetClipPlane(GlobalSceneGraph(), Plane3(0, 0, 0, 0));
243 AABB bounds(Vector3(0, 0, 0), Vector3(64, 64, 64));
244 PlanePointsFromClipPoints(planepts, bounds, g_clip_viewtype);
247 std::swap(planepts[0], planepts[1]);
249 Scene_BrushSetClipPlane(GlobalSceneGraph(), plane3_for_points(planepts[0], planepts[1], planepts[2]));
251 ClipperChangeNotify();
254 const char* Clip_getShader()
256 return g_clip_useCaulk ? "textures/common/caulk" : TextureBrowser_GetSelectedShader(GlobalTextureBrowser());
261 if (ClipMode() && GlobalClipPoints_valid())
264 AABB bounds(Vector3(0, 0, 0), Vector3(64, 64, 64));
265 PlanePointsFromClipPoints(planepts, bounds, g_clip_viewtype);
266 Scene_BrushSplitByPlane(GlobalSceneGraph(), planepts[0], planepts[1], planepts[2], Clip_getShader(), (!g_bSwitch) ? eFront : eBack);
271 ClipperChangeNotify();
277 if (ClipMode() && GlobalClipPoints_valid())
280 AABB bounds(Vector3(0, 0, 0), Vector3(64, 64, 64));
281 PlanePointsFromClipPoints(planepts, bounds, g_clip_viewtype);
282 Scene_BrushSplitByPlane(GlobalSceneGraph(), planepts[0], planepts[1], planepts[2], Clip_getShader(), eFrontAndBack);
287 ClipperChangeNotify();
293 g_bSwitch = !g_bSwitch;
295 ClipperChangeNotify();
298 void OnClipMode(bool enabled)
304 if(!enabled && g_pMovingClip)
310 ClipperChangeNotify();
315 return GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eClip;
318 void NewClipPoint(const Vector3& point)
320 if (g_Clip1.Set() == false)
322 g_Clip1.m_ptClip = point;
325 else if (g_Clip2.Set() == false)
327 g_Clip2.m_ptClip = point;
330 else if (g_Clip3.Set() == false)
332 g_Clip3.m_ptClip = point;
340 g_Clip1.m_ptClip = point;
345 ClipperChangeNotify();
350 struct xywindow_globals_private_t
354 // these are in the View > Show menu with Show coordinates
356 bool show_coordinates;
370 xywindow_globals_private_t() :
374 show_coordinates(true),
383 m_bCamXYUpdate(true),
391 xywindow_globals_t g_xywindow_globals;
392 xywindow_globals_private_t g_xywindow_globals_private;
394 const unsigned int RAD_NONE = 0x00;
395 const unsigned int RAD_SHIFT = 0x01;
396 const unsigned int RAD_ALT = 0x02;
397 const unsigned int RAD_CONTROL = 0x04;
398 const unsigned int RAD_PRESS = 0x08;
399 const unsigned int RAD_LBUTTON = 0x10;
400 const unsigned int RAD_MBUTTON = 0x20;
401 const unsigned int RAD_RBUTTON = 0x40;
403 inline ButtonIdentifier button_for_flags(unsigned int flags)
405 if(flags & RAD_LBUTTON)
407 if(flags & RAD_RBUTTON)
408 return c_buttonRight;
409 if(flags & RAD_MBUTTON)
410 return c_buttonMiddle;
411 return c_buttonInvalid;
414 inline ModifierFlags modifiers_for_flags(unsigned int flags)
416 ModifierFlags modifiers = c_modifierNone;
417 if(flags & RAD_SHIFT)
418 modifiers |= c_modifierShift;
419 if(flags & RAD_CONTROL)
420 modifiers |= c_modifierControl;
422 modifiers |= c_modifierAlt;
426 inline unsigned int buttons_for_button_and_modifiers(ButtonIdentifier button, ModifierFlags flags)
428 unsigned int buttons = 0;
430 switch (button.get())
432 case ButtonEnumeration::LEFT: buttons |= RAD_LBUTTON; break;
433 case ButtonEnumeration::MIDDLE: buttons |= RAD_MBUTTON; break;
434 case ButtonEnumeration::RIGHT: buttons |= RAD_RBUTTON; break;
437 if(bitfield_enabled(flags, c_modifierControl))
438 buttons |= RAD_CONTROL;
440 if(bitfield_enabled(flags, c_modifierShift))
441 buttons |= RAD_SHIFT;
443 if(bitfield_enabled(flags, c_modifierAlt))
449 inline unsigned int buttons_for_event_button(GdkEventButton* event)
451 unsigned int flags = 0;
453 switch (event->button)
455 case 1: flags |= RAD_LBUTTON; break;
456 case 2: flags |= RAD_MBUTTON; break;
457 case 3: flags |= RAD_RBUTTON; break;
460 if ((event->state & GDK_CONTROL_MASK) != 0)
461 flags |= RAD_CONTROL;
463 if ((event->state & GDK_SHIFT_MASK) != 0)
466 if((event->state & GDK_MOD1_MASK) != 0)
472 inline unsigned int buttons_for_state(guint state)
474 unsigned int flags = 0;
476 if ((state & GDK_BUTTON1_MASK) != 0)
477 flags |= RAD_LBUTTON;
479 if ((state & GDK_BUTTON2_MASK) != 0)
480 flags |= RAD_MBUTTON;
482 if ((state & GDK_BUTTON3_MASK) != 0)
483 flags |= RAD_RBUTTON;
485 if ((state & GDK_CONTROL_MASK) != 0)
486 flags |= RAD_CONTROL;
488 if ((state & GDK_SHIFT_MASK) != 0)
491 if ((state & GDK_MOD1_MASK) != 0)
498 void XYWnd::SetScale(float f)
506 void XYWnd_ZoomIn(XYWnd* xy)
508 float max_scale = 64;
509 float scale = xy->Scale() * 5.0f / 4.0f;
510 if(scale > max_scale)
512 if(xy->Scale() != max_scale)
514 xy->SetScale (max_scale);
524 // NOTE: the zoom out factor is 4/5, we could think about customizing it
525 // we don't go below a zoom factor corresponding to 10% of the max world size
526 // (this has to be computed against the window size)
527 void XYWnd_ZoomOut(XYWnd* xy)
529 float min_scale = MIN(xy->Width(),xy->Height()) / ( 1.1f * (g_MaxWorldCoord-g_MinWorldCoord));
530 float scale = xy->Scale() * 4.0f / 5.0f;
531 if(scale < min_scale)
533 if(xy->Scale() != min_scale)
535 xy->SetScale (min_scale);
544 VIEWTYPE GlobalXYWnd_getCurrentViewType()
546 ASSERT_NOTNULL(g_pParentWnd);
547 ASSERT_NOTNULL(g_pParentWnd->ActiveXY());
548 return g_pParentWnd->ActiveXY()->GetViewType();
551 // =============================================================================
554 bool g_bCrossHairs = false;
556 GtkMenu* XYWnd::m_mnuDrop = 0;
558 // this is disabled, and broken
559 // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=394
564 width = g_pParentWnd->ActiveXY()->Width();
565 height = g_pParentWnd->ActiveXY()->Height();
567 const char* filename;
569 filename = file_dialog(GTK_WIDGET(MainFrame_getWindow()), FALSE, "Save Image", 0, FILTER_BMP);
573 g_pParentWnd->ActiveXY()->MakeCurrent();
574 img = (unsigned char*)malloc (width*height*3);
575 glReadPixels (0,0,width,height,GL_RGB,GL_UNSIGNED_BYTE,img);
578 fp = fopen(filename, "wb");
582 unsigned long cmap, bfSize;
586 bfSize = 54 + width*height*3;
588 long byteswritten = 0;
589 long pixoff = 54 + cmap*4;
591 char m1 ='B', m2 ='M';
592 fwrite(&m1, 1, 1, fp); byteswritten++; // B
593 fwrite(&m2, 1, 1, fp); byteswritten++; // M
594 fwrite(&bfSize, 4, 1, fp); byteswritten+=4;// bfSize
595 fwrite(&res, 2, 1, fp); byteswritten+=2;// bfReserved1
596 fwrite(&res, 2, 1, fp); byteswritten+=2;// bfReserved2
597 fwrite(&pixoff, 4, 1, fp); byteswritten+=4;// bfOffBits
599 unsigned long biSize = 40, compress = 0, size = 0;
601 unsigned short planes = 1;
602 fwrite(&biSize, 4, 1, fp); byteswritten+=4;// biSize
603 fwrite(&width, 4, 1, fp); byteswritten+=4;// biWidth
604 fwrite(&height, 4, 1, fp); byteswritten+=4;// biHeight
605 fwrite(&planes, 2, 1, fp); byteswritten+=2;// biPlanes
606 fwrite(&bits, 2, 1, fp); byteswritten+=2;// biBitCount
607 fwrite(&compress, 4, 1, fp);byteswritten+=4;// biCompression
608 fwrite(&size, 4, 1, fp); byteswritten+=4;// biSizeImage
609 fwrite(&pixels, 4, 1, fp); byteswritten+=4;// biXPelsPerMeter
610 fwrite(&pixels, 4, 1, fp); byteswritten+=4;// biYPelsPerMeter
611 fwrite(&cmap, 4, 1, fp); byteswritten+=4;// biClrUsed
612 fwrite(&cmap, 4, 1, fp); byteswritten+=4;// biClrImportant
614 unsigned long widthDW = (((width*24) + 31) / 32 * 4);
615 long row, row_size = width*3;
616 for (row = 0; row < height; row++)
618 unsigned char* buf = img+row*row_size;
622 for (col = 0; col < row_size; col += 3)
624 putc(buf[col+2], fp);
625 putc(buf[col+1], fp);
628 byteswritten += row_size;
631 for (count = row_size; count < widthDW; count++)
633 putc(0, fp); // dummy
648 Timer g_chasemouse_timer;
650 void XYWnd::ChaseMouse()
652 float multiplier = g_chasemouse_timer.elapsed_msec() / 10.0f;
653 Scroll(float_to_integer(multiplier * m_chasemouse_delta_x), float_to_integer(multiplier * -m_chasemouse_delta_y));
655 //globalOutputStream() << "chasemouse: multiplier=" << multiplier << " x=" << m_chasemouse_delta_x << " y=" << m_chasemouse_delta_y << '\n';
657 XY_MouseMoved(m_chasemouse_current_x, m_chasemouse_current_y , getButtonState());
658 g_chasemouse_timer.start();
661 gboolean xywnd_chasemouse(gpointer data)
663 reinterpret_cast<XYWnd*>(data)->ChaseMouse();
667 inline const int& min_int(const int& left, const int& right)
669 return std::min(left, right);
672 bool XYWnd::chaseMouseMotion(int pointx, int pointy)
674 m_chasemouse_delta_x = 0;
675 m_chasemouse_delta_y = 0;
677 if (g_xywindow_globals_private.m_bChaseMouse && getButtonState() == RAD_LBUTTON)
679 const int epsilon = 16;
681 if (pointx < epsilon)
683 m_chasemouse_delta_x = std::max(pointx, 0) - epsilon;
685 else if ((pointx - m_nWidth) > -epsilon)
687 m_chasemouse_delta_x = min_int((pointx - m_nWidth), 0) + epsilon;
690 if (pointy < epsilon)
692 m_chasemouse_delta_y = std::max(pointy, 0) - epsilon;
694 else if ((pointy - m_nHeight) > -epsilon)
696 m_chasemouse_delta_y = min_int((pointy - m_nHeight), 0) + epsilon;
699 if(m_chasemouse_delta_y != 0 || m_chasemouse_delta_x != 0)
701 //globalOutputStream() << "chasemouse motion: x=" << pointx << " y=" << pointy << "... ";
702 m_chasemouse_current_x = pointx;
703 m_chasemouse_current_y = pointy;
704 if(m_chasemouse_handler == 0)
706 //globalOutputStream() << "chasemouse timer start... ";
707 g_chasemouse_timer.start();
708 m_chasemouse_handler = g_idle_add(xywnd_chasemouse, this);
714 if(m_chasemouse_handler != 0)
716 //globalOutputStream() << "chasemouse cancel\n";
717 g_source_remove(m_chasemouse_handler);
718 m_chasemouse_handler = 0;
724 if(m_chasemouse_handler != 0)
726 //globalOutputStream() << "chasemouse cancel\n";
727 g_source_remove(m_chasemouse_handler);
728 m_chasemouse_handler = 0;
734 // =============================================================================
736 Shader* XYWnd::m_state_selected = 0;
738 void xy_update_xor_rectangle(XYWnd& self, rect_t area)
740 if(GTK_WIDGET_VISIBLE(self.GetWidget()))
742 self.m_XORRectangle.set(rectangle_from_area(area.min, area.max, self.Width(), self.Height()));
746 gboolean xywnd_button_press(GtkWidget* widget, GdkEventButton* event, XYWnd* xywnd)
748 if(event->type == GDK_BUTTON_PRESS)
750 g_pParentWnd->SetActiveXY(xywnd);
752 xywnd->ButtonState_onMouseDown(buttons_for_event_button(event));
754 xywnd->onMouseDown(WindowVector(event->x, event->y), button_for_button(event->button), modifiers_for_state(event->state));
759 gboolean xywnd_button_release(GtkWidget* widget, GdkEventButton* event, XYWnd* xywnd)
761 if(event->type == GDK_BUTTON_RELEASE)
763 xywnd->XY_MouseUp(static_cast<int>(event->x), static_cast<int>(event->y), buttons_for_event_button(event));
765 xywnd->ButtonState_onMouseUp(buttons_for_event_button(event));
770 void xywnd_motion(gdouble x, gdouble y, guint state, void* data)
772 if(reinterpret_cast<XYWnd*>(data)->chaseMouseMotion(static_cast<int>(x), static_cast<int>(y)))
776 reinterpret_cast<XYWnd*>(data)->XY_MouseMoved(static_cast<int>(x), static_cast<int>(y), buttons_for_state(state));
779 gboolean xywnd_wheel_scroll(GtkWidget* widget, GdkEventScroll* event, XYWnd* xywnd)
781 if(event->direction == GDK_SCROLL_UP)
785 else if(event->direction == GDK_SCROLL_DOWN)
787 XYWnd_ZoomOut(xywnd);
792 gboolean xywnd_size_allocate(GtkWidget* widget, GtkAllocation* allocation, XYWnd* xywnd)
794 xywnd->m_nWidth = allocation->width;
795 xywnd->m_nHeight = allocation->height;
796 xywnd->updateProjection();
797 xywnd->m_window_observer->onSizeChanged(xywnd->Width(), xywnd->Height());
801 gboolean xywnd_expose(GtkWidget* widget, GdkEventExpose* event, XYWnd* xywnd)
803 if(glwidget_make_current(xywnd->GetWidget()) != FALSE)
805 if(Map_Valid(g_map) && ScreenUpdates_Enabled())
807 GlobalOpenGL_debugAssertNoErrors();
809 GlobalOpenGL_debugAssertNoErrors();
811 xywnd->m_XORRectangle.set(rectangle_t());
813 glwidget_swap_buffers(xywnd->GetWidget());
819 void XYWnd_CameraMoved(XYWnd& xywnd)
821 if(g_xywindow_globals_private.m_bCamXYUpdate)
828 m_gl_widget(glwidget_new(FALSE)),
829 m_deferredDraw(WidgetQueueDrawCaller(*m_gl_widget)),
830 m_deferred_motion(xywnd_motion, this),
832 m_window_observer(NewWindowObserver()),
833 m_XORRectangle(m_gl_widget),
834 m_chasemouse_handler(0)
839 m_bNewBrushDrag = false;
840 m_move_started = false;
841 m_zoom_started = false;
852 m_entityCreate = false;
856 GlobalWindowObservers_add(m_window_observer);
857 GlobalWindowObservers_connectWidget(m_gl_widget);
859 m_window_observer->setRectangleDrawCallback(ReferenceCaller1<XYWnd, rect_t, xy_update_xor_rectangle>(*this));
860 m_window_observer->setView(m_view);
862 gtk_widget_ref(m_gl_widget);
864 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);
865 GTK_WIDGET_SET_FLAGS(m_gl_widget, GTK_CAN_FOCUS);
867 m_sizeHandler = g_signal_connect(G_OBJECT(m_gl_widget), "size_allocate", G_CALLBACK(xywnd_size_allocate), this);
868 m_exposeHandler = g_signal_connect(G_OBJECT(m_gl_widget), "expose_event", G_CALLBACK(xywnd_expose), this);
870 g_signal_connect(G_OBJECT(m_gl_widget), "button_press_event", G_CALLBACK(xywnd_button_press), this);
871 g_signal_connect(G_OBJECT(m_gl_widget), "button_release_event", G_CALLBACK(xywnd_button_release), this);
872 g_signal_connect(G_OBJECT(m_gl_widget), "motion_notify_event", G_CALLBACK(DeferredMotion::gtk_motion), &m_deferred_motion);
874 g_signal_connect(G_OBJECT(m_gl_widget), "scroll_event", G_CALLBACK(xywnd_wheel_scroll), this);
876 Map_addValidCallback(g_map, DeferredDrawOnMapValidChangedCaller(m_deferredDraw));
881 AddSceneChangeCallback(ReferenceCaller<XYWnd, &XYWnd_Update>(*this));
882 AddCameraMovedCallback(ReferenceCaller<XYWnd, &XYWnd_CameraMoved>(*this));
884 PressedButtons_connect(g_pressedButtons, m_gl_widget);
886 onMouseDown.connectLast(makeSignalHandler3(MouseDownCaller(), *this));
895 gtk_widget_destroy(GTK_WIDGET(m_mnuDrop));
899 g_signal_handler_disconnect(G_OBJECT(m_gl_widget), m_sizeHandler);
900 g_signal_handler_disconnect(G_OBJECT(m_gl_widget), m_exposeHandler);
902 gtk_widget_unref(m_gl_widget);
904 m_window_observer->release();
907 void XYWnd::captureStates()
909 m_state_selected = GlobalShaderCache().capture("$XY_OVERLAY");
912 void XYWnd::releaseStates()
914 GlobalShaderCache().release("$XY_OVERLAY");
917 const Vector3& XYWnd::GetOrigin()
922 void XYWnd::SetOrigin(const Vector3& origin)
928 void XYWnd::Scroll(int x, int y)
930 int nDim1 = (m_viewType == YZ) ? 1 : 0;
931 int nDim2 = (m_viewType == XY) ? 1 : 2;
932 m_vOrigin[nDim1] += x / m_fScale;
933 m_vOrigin[nDim2] += y / m_fScale;
938 unsigned int Clipper_buttons()
943 void XYWnd::DropClipPoint(int pointx, int pointy)
947 XY_ToPoint(pointx, pointy, point);
951 g_clip_viewtype = static_cast<VIEWTYPE>(GetViewType());
952 int nDim = (g_clip_viewtype == YZ ) ? nDim = 0 : ( (g_clip_viewtype == XZ) ? nDim = 1 : nDim = 2 );
953 point[nDim] = mid[nDim];
954 vector3_snap(point, GetGridSize());
958 void XYWnd::Clipper_OnLButtonDown(int x, int y)
960 Vector3 mousePosition;
961 XY_ToPoint(x, y , mousePosition);
962 g_pMovingClip = GlobalClipPoints_Find(mousePosition, (VIEWTYPE)m_viewType, m_fScale);
969 void XYWnd::Clipper_OnLButtonUp(int x, int y)
977 void XYWnd::Clipper_OnMouseMoved(int x, int y)
981 XY_ToPoint(x, y , g_pMovingClip->m_ptClip);
982 XY_SnapToGrid(g_pMovingClip->m_ptClip);
984 ClipperChangeNotify();
988 void XYWnd::Clipper_Crosshair_OnMouseMoved(int x, int y)
990 Vector3 mousePosition;
991 XY_ToPoint(x, y , mousePosition);
992 if(ClipMode() && GlobalClipPoints_Find(mousePosition, (VIEWTYPE)m_viewType, m_fScale) != 0)
995 cursor = gdk_cursor_new (GDK_CROSSHAIR);
996 gdk_window_set_cursor (m_gl_widget->window, cursor);
997 gdk_cursor_unref (cursor);
1001 gdk_window_set_cursor (m_gl_widget->window, 0);
1005 unsigned int MoveCamera_buttons()
1007 return RAD_CONTROL | (g_glwindow_globals.m_nMouseType == ETwoButton ? RAD_RBUTTON : RAD_MBUTTON);
1010 void XYWnd_PositionCamera(XYWnd* xywnd, int x, int y, CamWnd& camwnd)
1012 Vector3 origin(Camera_getOrigin(camwnd));
1013 xywnd->XY_ToPoint(x, y, origin);
1014 xywnd->XY_SnapToGrid(origin);
1015 Camera_setOrigin(camwnd, origin);
1018 unsigned int OrientCamera_buttons()
1020 if(g_glwindow_globals.m_nMouseType == ETwoButton)
1021 return RAD_RBUTTON | RAD_SHIFT | RAD_CONTROL;
1025 void XYWnd_OrientCamera(XYWnd* xywnd, int x, int y, CamWnd& camwnd)
1027 Vector3 point = g_vector3_identity;
1028 xywnd->XY_ToPoint(x, y, point);
1029 xywnd->XY_SnapToGrid(point);
1030 vector3_subtract(point, Camera_getOrigin(camwnd));
1032 int n1 = (xywnd->GetViewType() == XY) ? 1 : 2;
1033 int n2 = (xywnd->GetViewType() == YZ) ? 1 : 0;
1034 int nAngle = (xywnd->GetViewType() == XY) ? CAMERA_YAW : CAMERA_PITCH;
1035 if (point[n1] || point[n2])
1037 Vector3 angles(Camera_getAngles(camwnd));
1038 angles[nAngle] = static_cast<float>(radians_to_degrees(atan2 (point[n1], point[n2])));
1039 Camera_setAngles(camwnd, angles);
1048 unsigned int NewBrushDrag_buttons()
1053 void XYWnd::NewBrushDrag_Begin(int x, int y)
1056 m_nNewBrushPressx = x;
1057 m_nNewBrushPressy = y;
1059 m_bNewBrushDrag = true;
1060 GlobalUndoSystem().start();
1063 void XYWnd::NewBrushDrag_End(int x, int y)
1065 if(m_NewBrushDrag != 0)
1067 GlobalUndoSystem().finish("brushDragNew");
1071 void XYWnd::NewBrushDrag(int x, int y)
1074 XY_ToPoint(m_nNewBrushPressx, m_nNewBrushPressy, mins);
1075 XY_SnapToGrid(mins);
1076 XY_ToPoint(x, y, maxs);
1077 XY_SnapToGrid(maxs);
1079 int nDim = (m_viewType == XY) ? 2 : (m_viewType == YZ) ? 0 : 1;
1081 mins[nDim] = float_snapped(Select_getWorkZone().d_work_min[nDim], GetGridSize());
1082 maxs[nDim] = float_snapped(Select_getWorkZone().d_work_max[nDim], GetGridSize());
1084 if (maxs[nDim] <= mins[nDim])
1085 maxs[nDim] = mins[nDim] + GetGridSize();
1087 for(int i=0 ; i<3 ; i++)
1089 if (mins[i] == maxs[i])
1090 return; // don't create a degenerate brush
1091 if (mins[i] > maxs[i])
1093 float temp = mins[i];
1099 if(m_NewBrushDrag == 0)
1101 NodeSmartReference node(GlobalBrushCreator().createBrush());
1102 Node_getTraversable(Map_FindOrInsertWorldspawn(g_map))->insert(node);
1104 scene::Path brushpath(makeReference(GlobalSceneGraph().root()));
1105 brushpath.push(makeReference(*Map_GetWorldspawn(g_map)));
1106 brushpath.push(makeReference(node.get()));
1107 selectPath(brushpath, true);
1109 m_NewBrushDrag = node.get_pointer();
1112 Scene_BrushResize_Selected(GlobalSceneGraph(), aabb_for_minmax(mins, maxs), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()));
1115 void entitycreate_activated(GtkWidget* item)
1117 scene::Node* world_node = Map_FindWorldspawn(g_map);
1118 const char* entity_name = gtk_label_get_text(GTK_LABEL(GTK_BIN(item)->child));
1120 if(!(world_node && string_equal(entity_name, "worldspawn")))
1122 g_pParentWnd->ActiveXY()->OnEntityCreate(entity_name);
1124 GlobalRadiant().m_pfnMessageBox(GTK_WIDGET(MainFrame_getWindow()), "There's already a worldspawn in your map!"
1132 void EntityClassMenu_addItem(GtkMenu* menu, const char* name)
1134 GtkMenuItem* item = GTK_MENU_ITEM(gtk_menu_item_new_with_label(name));
1135 g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(entitycreate_activated), item);
1136 gtk_widget_show(GTK_WIDGET(item));
1137 menu_add_item(menu, item);
1140 class EntityClassMenuInserter : public EntityClassVisitor
1142 typedef std::pair<GtkMenu*, CopiedString> MenuPair;
1143 typedef std::vector<MenuPair> MenuStack;
1145 CopiedString m_previous;
1147 EntityClassMenuInserter(GtkMenu* menu)
1150 m_stack.push_back(MenuPair(menu, ""));
1152 ~EntityClassMenuInserter()
1154 if(!string_empty(m_previous.c_str()))
1156 addItem(m_previous.c_str(), "");
1159 void visit(EntityClass* e)
1161 ASSERT_MESSAGE(!string_empty(e->name()), "entity-class has no name");
1162 if(!string_empty(m_previous.c_str()))
1164 addItem(m_previous.c_str(), e->name());
1166 m_previous = e->name();
1168 void pushMenu(const CopiedString& name)
1170 GtkMenuItem* item = GTK_MENU_ITEM(gtk_menu_item_new_with_label(name.c_str()));
1171 gtk_widget_show(GTK_WIDGET(item));
1172 container_add_widget(GTK_CONTAINER(m_stack.back().first), GTK_WIDGET(item));
1174 GtkMenu* submenu = GTK_MENU(gtk_menu_new());
1175 gtk_menu_item_set_submenu(item, GTK_WIDGET(submenu));
1177 m_stack.push_back(MenuPair(submenu, name));
1183 void addItem(const char* name, const char* next)
1185 const char* underscore = strchr(name, '_');
1187 if(underscore != 0 && underscore != name)
1189 bool nextEqual = string_equal_n(name, next, (underscore + 1) - name);
1190 const char* parent = m_stack.back().second.c_str();
1192 if(!string_empty(parent)
1193 && string_length(parent) == std::size_t(underscore - name)
1194 && string_equal_n(name, parent, underscore - name)) // this is a child
1199 if(m_stack.size() == 2)
1203 pushMenu(CopiedString(StringRange(name, underscore)));
1205 else if(m_stack.size() == 2)
1210 else if(m_stack.size() == 2)
1215 EntityClassMenu_addItem(m_stack.back().first, name);
1219 void XYWnd::OnContextMenu()
1221 if (g_xywindow_globals.m_bRightClick == false)
1224 if (m_mnuDrop == 0) // first time, load it up
1226 GtkMenu* menu = m_mnuDrop = GTK_MENU(gtk_menu_new());
1228 EntityClassMenuInserter inserter(menu);
1229 GlobalEntityClassManager().forEach(inserter);
1232 gtk_menu_popup(m_mnuDrop, 0, 0, 0, 0, 1, GDK_CURRENT_TIME);
1235 FreezePointer g_xywnd_freezePointer;
1237 unsigned int Move_buttons()
1242 void XYWnd_moveDelta(int x, int y, unsigned int state, void* data)
1244 reinterpret_cast<XYWnd*>(data)->EntityCreate_MouseMove(x, y);
1245 reinterpret_cast<XYWnd*>(data)->Scroll(-x, y);
1248 gboolean XYWnd_Move_focusOut(GtkWidget* widget, GdkEventFocus* event, XYWnd* xywnd)
1254 void XYWnd::Move_Begin()
1260 m_move_started = true;
1261 g_xywnd_freezePointer.freeze_pointer(m_parent != 0 ? m_parent : MainFrame_getWindow(), XYWnd_moveDelta, this);
1262 m_move_focusOut = g_signal_connect(G_OBJECT(m_gl_widget), "focus_out_event", G_CALLBACK(XYWnd_Move_focusOut), this);
1265 void XYWnd::Move_End()
1267 m_move_started = false;
1268 g_xywnd_freezePointer.unfreeze_pointer(m_parent != 0 ? m_parent : MainFrame_getWindow());
1269 g_signal_handler_disconnect(G_OBJECT(m_gl_widget), m_move_focusOut);
1272 unsigned int Zoom_buttons()
1274 return RAD_RBUTTON | RAD_SHIFT;
1279 void XYWnd_zoomDelta(int x, int y, unsigned int state, void* data)
1285 while(abs(g_dragZoom) > 8)
1289 XYWnd_ZoomOut(reinterpret_cast<XYWnd*>(data));
1294 XYWnd_ZoomIn(reinterpret_cast<XYWnd*>(data));
1301 gboolean XYWnd_Zoom_focusOut(GtkWidget* widget, GdkEventFocus* event, XYWnd* xywnd)
1307 void XYWnd::Zoom_Begin()
1313 m_zoom_started = true;
1315 g_xywnd_freezePointer.freeze_pointer(m_parent != 0 ? m_parent : MainFrame_getWindow(), XYWnd_zoomDelta, this);
1316 m_zoom_focusOut = g_signal_connect(G_OBJECT(m_gl_widget), "focus_out_event", G_CALLBACK(XYWnd_Zoom_focusOut), this);
1319 void XYWnd::Zoom_End()
1321 m_zoom_started = false;
1322 g_xywnd_freezePointer.unfreeze_pointer(m_parent != 0 ? m_parent : MainFrame_getWindow());
1323 g_signal_handler_disconnect(G_OBJECT(m_gl_widget), m_zoom_focusOut);
1326 // makes sure the selected brush or camera is in view
1327 void XYWnd::PositionView(const Vector3& position)
1329 int nDim1 = (m_viewType == YZ) ? 1 : 0;
1330 int nDim2 = (m_viewType == XY) ? 1 : 2;
1332 m_vOrigin[nDim1] = position[nDim1];
1333 m_vOrigin[nDim2] = position[nDim2];
1337 XYWnd_Update(*this);
1340 void XYWnd::SetViewType(VIEWTYPE viewType)
1342 m_viewType = viewType;
1347 gtk_window_set_title(m_parent, ViewType_getTitle(m_viewType));
1352 inline WindowVector WindowVector_forInteger(int x, int y)
1354 return WindowVector(static_cast<float>(x), static_cast<float>(y));
1357 void XYWnd::mouseDown(const WindowVector& position, ButtonIdentifier button, ModifierFlags modifiers)
1359 XY_MouseDown(static_cast<int>(position.x()), static_cast<int>(position.y()), buttons_for_button_and_modifiers(button, modifiers));
1361 void XYWnd::XY_MouseDown (int x, int y, unsigned int buttons)
1363 if(buttons == Move_buttons())
1366 EntityCreate_MouseDown(x, y);
1368 else if(buttons == Zoom_buttons())
1372 else if(ClipMode() && buttons == Clipper_buttons())
1374 Clipper_OnLButtonDown(x, y);
1376 else if(buttons == NewBrushDrag_buttons() && GlobalSelectionSystem().countSelected() == 0)
1378 NewBrushDrag_Begin(x, y);
1380 // control mbutton = move camera
1381 else if (buttons == MoveCamera_buttons())
1383 XYWnd_PositionCamera(this, x, y, *g_pParentWnd->GetCamWnd());
1385 // mbutton = angle camera
1386 else if(buttons == OrientCamera_buttons())
1388 XYWnd_OrientCamera(this, x, y, *g_pParentWnd->GetCamWnd());
1392 m_window_observer->onMouseDown(WindowVector_forInteger(x, y), button_for_flags(buttons), modifiers_for_flags(buttons));
1396 void XYWnd::XY_MouseUp(int x, int y, unsigned int buttons)
1401 EntityCreate_MouseUp(x, y);
1403 else if(m_zoom_started)
1407 else if (ClipMode() && buttons == Clipper_buttons())
1409 Clipper_OnLButtonUp(x, y);
1411 else if (m_bNewBrushDrag)
1413 m_bNewBrushDrag = false;
1414 NewBrushDrag_End(x, y);
1418 m_window_observer->onMouseUp(WindowVector_forInteger(x, y), button_for_flags(buttons), modifiers_for_flags(buttons));
1422 void XYWnd::XY_MouseMoved (int x, int y, unsigned int buttons)
1424 // rbutton = drag xy origin
1429 else if(m_zoom_started)
1433 else if (ClipMode() && g_pMovingClip != 0)
1435 Clipper_OnMouseMoved(x, y);
1437 // lbutton without selection = drag new brush
1438 else if (m_bNewBrushDrag)
1443 // control mbutton = move camera
1444 else if (getButtonState() == MoveCamera_buttons())
1446 XYWnd_PositionCamera(this, x, y, *g_pParentWnd->GetCamWnd());
1449 // mbutton = angle camera
1450 else if (getButtonState() == OrientCamera_buttons())
1452 XYWnd_OrientCamera(this, x, y, *g_pParentWnd->GetCamWnd());
1457 m_window_observer->onMouseMotion(WindowVector_forInteger(x, y), modifiers_for_flags(buttons));
1459 m_mousePosition[0] = m_mousePosition[1] = m_mousePosition[2] = 0.0;
1460 XY_ToPoint(x, y , m_mousePosition);
1461 XY_SnapToGrid(m_mousePosition);
1463 StringOutputStream status(64);
1464 status << "x:: " << FloatFormat(m_mousePosition[0], 6, 1)
1465 << " y:: " << FloatFormat(m_mousePosition[1], 6, 1)
1466 << " z:: " << FloatFormat(m_mousePosition[2], 6, 1);
1467 g_pParentWnd->SetStatusText(g_pParentWnd->m_position_status, status.c_str());
1471 XYWnd_Update(*this);
1474 Clipper_Crosshair_OnMouseMoved(x, y);
1478 void XYWnd::EntityCreate_MouseDown(int x, int y)
1480 m_entityCreate = true;
1481 m_entityCreate_x = x;
1482 m_entityCreate_y = y;
1485 void XYWnd::EntityCreate_MouseMove(int x, int y)
1487 if(m_entityCreate && (m_entityCreate_x != x || m_entityCreate_y != y))
1489 m_entityCreate = false;
1493 void XYWnd::EntityCreate_MouseUp(int x, int y)
1497 m_entityCreate = false;
1502 inline float screen_normalised(int pos, unsigned int size)
1504 return ((2.0f * pos) / size) - 1.0f;
1507 inline float normalised_to_world(float normalised, float world_origin, float normalised2world_scale)
1509 return world_origin + normalised * normalised2world_scale;
1513 // TTimo: watch it, this doesn't init one of the 3 coords
1514 void XYWnd::XY_ToPoint (int x, int y, Vector3& point)
1516 float normalised2world_scale_x = m_nWidth / 2 / m_fScale;
1517 float normalised2world_scale_y = m_nHeight / 2 / m_fScale;
1518 if (m_viewType == XY)
1520 point[0] = normalised_to_world(screen_normalised(x, m_nWidth), m_vOrigin[0], normalised2world_scale_x);
1521 point[1] = normalised_to_world(-screen_normalised(y, m_nHeight), m_vOrigin[1], normalised2world_scale_y);
1523 else if (m_viewType == YZ)
1525 point[1] = normalised_to_world(screen_normalised(x, m_nWidth), m_vOrigin[1], normalised2world_scale_x);
1526 point[2] = normalised_to_world(-screen_normalised(y, m_nHeight), m_vOrigin[2], normalised2world_scale_y);
1530 point[0] = normalised_to_world(screen_normalised(x, m_nWidth), m_vOrigin[0], normalised2world_scale_x);
1531 point[2] = normalised_to_world(-screen_normalised(y, m_nHeight), m_vOrigin[2], normalised2world_scale_y);
1535 void XYWnd::XY_SnapToGrid(Vector3& point)
1537 if (m_viewType == XY)
1539 point[0] = float_snapped(point[0], GetGridSize());
1540 point[1] = float_snapped(point[1], GetGridSize());
1542 else if (m_viewType == YZ)
1544 point[1] = float_snapped(point[1], GetGridSize());
1545 point[2] = float_snapped(point[2], GetGridSize());
1549 point[0] = float_snapped(point[0], GetGridSize());
1550 point[2] = float_snapped(point[2], GetGridSize());
1555 ============================================================================
1559 ============================================================================
1568 double two_to_the_power(int power)
1570 return pow(2.0f, power);
1573 void XYWnd::XY_DrawGrid()
1575 float x, y, xb, xe, yb, ye;
1578 float step, minor_step, stepx, stepy;
1579 step = minor_step = stepx = stepy = GetGridSize();
1581 int minor_power = Grid_getPower();
1584 while((minor_step * m_fScale) <= 4.0f) // make sure minor grid spacing is at least 4 pixels on the screen
1589 int power = minor_power;
1590 while((power % 3) != 0 || (step * m_fScale) <= 32.0f) // make sure major grid spacing is at least 32 pixels on the screen
1593 step = float(two_to_the_power(power));
1595 mask = (1 << (power - minor_power)) - 1;
1596 while ((stepx * m_fScale) <= 32.0f) // text step x must be at least 32
1598 while ((stepy * m_fScale) <= 32.0f) // text step y must be at least 32
1602 glDisable(GL_TEXTURE_2D);
1603 glDisable(GL_TEXTURE_1D);
1604 glDisable(GL_DEPTH_TEST);
1605 glDisable(GL_BLEND);
1608 w = (m_nWidth / 2 / m_fScale);
1609 h = (m_nHeight / 2 / m_fScale);
1611 int nDim1 = (m_viewType == YZ) ? 1 : 0;
1612 int nDim2 = (m_viewType == XY) ? 1 : 2;
1614 xb = m_vOrigin[nDim1] - w;
1615 if (xb < region_mins[nDim1])
1616 xb = region_mins[nDim1];
1617 xb = step * floor (xb/step);
1619 xe = m_vOrigin[nDim1] + w;
1620 if (xe > region_maxs[nDim1])
1621 xe = region_maxs[nDim1];
1622 xe = step * ceil (xe/step);
1624 yb = m_vOrigin[nDim2] - h;
1625 if (yb < region_mins[nDim2])
1626 yb = region_mins[nDim2];
1627 yb = step * floor (yb/step);
1629 ye = m_vOrigin[nDim2] + h;
1630 if (ye > region_maxs[nDim2])
1631 ye = region_maxs[nDim2];
1632 ye = step * ceil (ye/step);
1634 #define COLORS_DIFFER(a,b) \
1635 ((a)[0] != (b)[0] || \
1636 (a)[1] != (b)[1] || \
1640 // draw minor blocks
1641 if (g_xywindow_globals_private.d_showgrid)
1643 if (COLORS_DIFFER(g_xywindow_globals.color_gridminor, g_xywindow_globals.color_gridback))
1645 glColor3fv(vector3_to_array(g_xywindow_globals.color_gridminor));
1649 for (x = xb ; x < xe ; x += minor_step, ++i)
1658 for (y = yb ; y < ye ; y += minor_step, ++i)
1669 // draw major blocks
1670 if (COLORS_DIFFER(g_xywindow_globals.color_gridmajor, g_xywindow_globals.color_gridback))
1672 glColor3fv(vector3_to_array(g_xywindow_globals.color_gridmajor));
1675 for (x=xb ; x<=xe ; x+=step)
1680 for (y=yb ; y<=ye ; y+=step)
1689 // draw coordinate text if needed
1690 if ( g_xywindow_globals_private.show_coordinates)
1692 glColor3fv(vector3_to_array(g_xywindow_globals.color_gridtext));
1693 float offx = m_vOrigin[nDim2] + h - 6 / m_fScale, offy = m_vOrigin[nDim1] - w + 1 / m_fScale;
1694 for (x = xb - fmod(xb, stepx); x <= xe ; x += stepx)
1696 glRasterPos2f (x, offx);
1697 sprintf (text, "%g", x);
1698 GlobalOpenGL().drawString(text);
1700 for (y = yb - fmod(yb, stepy); y <= ye ; y += stepy)
1702 glRasterPos2f (offy, y);
1703 sprintf (text, "%g", y);
1704 GlobalOpenGL().drawString(text);
1708 glColor3fv(vector3_to_array(g_xywindow_globals.color_viewname));
1710 // we do this part (the old way) only if show_axis is disabled
1711 if (!g_xywindow_globals_private.show_axis)
1713 glRasterPos2f ( m_vOrigin[nDim1] - w + 35 / m_fScale, m_vOrigin[nDim2] + h - 20 / m_fScale );
1715 GlobalOpenGL().drawString(ViewType_getTitle(m_viewType));
1719 if ( g_xywindow_globals_private.show_axis)
1721 const char g_AxisName[3] = { 'X', 'Y', 'Z' };
1723 const Vector3& colourX = (m_viewType == YZ) ? g_xywindow_globals.AxisColorY : g_xywindow_globals.AxisColorX;
1724 const Vector3& colourY = (m_viewType == XY) ? g_xywindow_globals.AxisColorY : g_xywindow_globals.AxisColorZ;
1726 // draw two lines with corresponding axis colors to highlight current view
1727 // horizontal line: nDim1 color
1729 glBegin( GL_LINES );
1730 glColor3fv (vector3_to_array(colourX));
1731 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1732 glVertex2f( m_vOrigin[nDim1] - w + 65 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1734 glVertex2f( 32 / m_fScale, 0 );
1735 glColor3fv (vector3_to_array(colourY));
1736 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1737 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 20 / m_fScale );
1739 glVertex2f( 0, 32 / m_fScale );
1742 // now print axis symbols
1743 glColor3fv (vector3_to_array(colourX));
1744 glRasterPos2f ( m_vOrigin[nDim1] - w + 55 / m_fScale, m_vOrigin[nDim2] + h - 55 / m_fScale );
1745 GlobalOpenGL().drawChar(g_AxisName[nDim1]);
1746 glRasterPos2f (28 / m_fScale, -10 / m_fScale );
1747 GlobalOpenGL().drawChar(g_AxisName[nDim1]);
1748 glColor3fv (vector3_to_array(colourY));
1749 glRasterPos2f ( m_vOrigin[nDim1] - w + 25 / m_fScale, m_vOrigin[nDim2] + h - 30 / m_fScale );
1750 GlobalOpenGL().drawChar(g_AxisName[nDim2]);
1751 glRasterPos2f ( -10 / m_fScale, 28 / m_fScale );
1752 GlobalOpenGL().drawChar(g_AxisName[nDim2]);
1756 // show current work zone?
1757 // the work zone is used to place dropped points and brushes
1758 if (g_xywindow_globals_private.d_show_work)
1760 glColor3f( 1.0f, 0.0f, 0.0f );
1761 glBegin( GL_LINES );
1762 glVertex2f( xb, Select_getWorkZone().d_work_min[nDim2] );
1763 glVertex2f( xe, Select_getWorkZone().d_work_min[nDim2] );
1764 glVertex2f( xb, Select_getWorkZone().d_work_max[nDim2] );
1765 glVertex2f( xe, Select_getWorkZone().d_work_max[nDim2] );
1766 glVertex2f( Select_getWorkZone().d_work_min[nDim1], yb );
1767 glVertex2f( Select_getWorkZone().d_work_min[nDim1], ye );
1768 glVertex2f( Select_getWorkZone().d_work_max[nDim1], yb );
1769 glVertex2f( Select_getWorkZone().d_work_max[nDim1], ye );
1779 void XYWnd::XY_DrawBlockGrid()
1781 if(Map_FindWorldspawn(g_map) == 0)
1785 const char *value = Node_getEntity(*Map_GetWorldspawn(g_map))->getKeyValue("_blocksize" );
1787 sscanf( value, "%i", &g_xywindow_globals_private.blockSize );
1789 if (!g_xywindow_globals_private.blockSize || g_xywindow_globals_private.blockSize > 65536 || g_xywindow_globals_private.blockSize < 1024)
1790 // don't use custom blocksize if it is less than the default, or greater than the maximum world coordinate
1791 g_xywindow_globals_private.blockSize = 1024;
1793 float x, y, xb, xe, yb, ye;
1797 glDisable(GL_TEXTURE_2D);
1798 glDisable(GL_TEXTURE_1D);
1799 glDisable(GL_DEPTH_TEST);
1800 glDisable(GL_BLEND);
1802 w = (m_nWidth / 2 / m_fScale);
1803 h = (m_nHeight / 2 / m_fScale);
1805 int nDim1 = (m_viewType == YZ) ? 1 : 0;
1806 int nDim2 = (m_viewType == XY) ? 1 : 2;
1808 xb = m_vOrigin[nDim1] - w;
1809 if (xb < region_mins[nDim1])
1810 xb = region_mins[nDim1];
1811 xb = static_cast<float>(g_xywindow_globals_private.blockSize * floor (xb/g_xywindow_globals_private.blockSize));
1813 xe = m_vOrigin[nDim1] + w;
1814 if (xe > region_maxs[nDim1])
1815 xe = region_maxs[nDim1];
1816 xe = static_cast<float>(g_xywindow_globals_private.blockSize * ceil (xe/g_xywindow_globals_private.blockSize));
1818 yb = m_vOrigin[nDim2] - h;
1819 if (yb < region_mins[nDim2])
1820 yb = region_mins[nDim2];
1821 yb = static_cast<float>(g_xywindow_globals_private.blockSize * floor (yb/g_xywindow_globals_private.blockSize));
1823 ye = m_vOrigin[nDim2] + h;
1824 if (ye > region_maxs[nDim2])
1825 ye = region_maxs[nDim2];
1826 ye = static_cast<float>(g_xywindow_globals_private.blockSize * ceil (ye/g_xywindow_globals_private.blockSize));
1828 // draw major blocks
1830 glColor3fv(vector3_to_array(g_xywindow_globals.color_gridblock));
1835 for (x=xb ; x<=xe ; x+=g_xywindow_globals_private.blockSize)
1841 if (m_viewType == XY)
1843 for (y=yb ; y<=ye ; y+=g_xywindow_globals_private.blockSize)
1853 // draw coordinate text if needed
1855 if (m_viewType == XY && m_fScale > .1)
1857 for (x=xb ; x<xe ; x+=g_xywindow_globals_private.blockSize)
1858 for (y=yb ; y<ye ; y+=g_xywindow_globals_private.blockSize)
1860 glRasterPos2f (x+(g_xywindow_globals_private.blockSize/2), y+(g_xywindow_globals_private.blockSize/2));
1861 sprintf (text, "%i,%i",(int)floor(x/g_xywindow_globals_private.blockSize), (int)floor(y/g_xywindow_globals_private.blockSize) );
1862 GlobalOpenGL().drawString(text);
1866 glColor4f(0, 0, 0, 0);
1869 void XYWnd::DrawCameraIcon(const Vector3& origin, const Vector3& angles)
1871 float x, y, fov, box;
1874 fov = 48 / m_fScale;
1875 box = 16 / m_fScale;
1877 if (m_viewType == XY)
1881 a = degrees_to_radians(angles[CAMERA_YAW]);
1883 else if (m_viewType == YZ)
1887 a = degrees_to_radians(angles[CAMERA_PITCH]);
1893 a = degrees_to_radians(angles[CAMERA_PITCH]);
1896 glColor3f (0.0, 0.0, 1.0);
1897 glBegin(GL_LINE_STRIP);
1898 glVertex3f (x-box,y,0);
1899 glVertex3f (x,y+(box/2),0);
1900 glVertex3f (x+box,y,0);
1901 glVertex3f (x,y-(box/2),0);
1902 glVertex3f (x-box,y,0);
1903 glVertex3f (x+box,y,0);
1906 glBegin(GL_LINE_STRIP);
1907 glVertex3f (x + static_cast<float>(fov*cos(a+c_pi/4)), y + static_cast<float>(fov*sin(a+c_pi/4)), 0);
1908 glVertex3f (x, y, 0);
1909 glVertex3f (x + static_cast<float>(fov*cos(a-c_pi/4)), y + static_cast<float>(fov*sin(a-c_pi/4)), 0);
1915 float Betwixt(float f1, float f2)
1918 return f2 + ((f1 - f2) / 2);
1920 return f1 + ((f2 - f1) / 2);
1924 // can be greatly simplified but per usual i am in a hurry
1925 // which is not an excuse, just a fact
1926 void XYWnd::PaintSizeInfo(int nDim1, int nDim2, Vector3& vMinBounds, Vector3& vMaxBounds)
1928 if(vector3_equal(vMinBounds, vMaxBounds))
1932 const char* g_pDimStrings[] = {"x:", "y:", "z:"};
1933 typedef const char* OrgStrings[2];
1934 const OrgStrings g_pOrgStrings[] = { { "x:", "y:", }, { "x:", "z:", }, { "y:", "z:", } };
1936 Vector3 vSize(vector3_subtracted(vMaxBounds, vMinBounds));
1938 glColor3f(g_xywindow_globals.color_selbrushes[0] * .65f,
1939 g_xywindow_globals.color_selbrushes[1] * .65f,
1940 g_xywindow_globals.color_selbrushes[2] * .65f);
1942 StringOutputStream dimensions(16);
1944 if (m_viewType == XY)
1948 glVertex3f(vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f);
1949 glVertex3f(vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f);
1951 glVertex3f(vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f);
1952 glVertex3f(vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f);
1954 glVertex3f(vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f);
1955 glVertex3f(vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f);
1958 glVertex3f(vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2], 0.0f);
1959 glVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f);
1961 glVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f);
1962 glVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f);
1964 glVertex3f(vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2], 0.0f);
1965 glVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f);
1969 glRasterPos3f (Betwixt(vMinBounds[nDim1], vMaxBounds[nDim1]), vMinBounds[nDim2] - 20.0f / m_fScale, 0.0f);
1970 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
1971 GlobalOpenGL().drawString(dimensions.c_str());
1974 glRasterPos3f (vMaxBounds[nDim1] + 16.0f / m_fScale, Betwixt(vMinBounds[nDim2], vMaxBounds[nDim2]), 0.0f);
1975 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
1976 GlobalOpenGL().drawString(dimensions.c_str());
1979 glRasterPos3f (vMinBounds[nDim1] + 4, vMaxBounds[nDim2] + 8 / m_fScale, 0.0f);
1980 dimensions << "(" << g_pOrgStrings[0][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[0][1] << vMaxBounds[nDim2] << ")";
1981 GlobalOpenGL().drawString(dimensions.c_str());
1983 else if (m_viewType == XZ)
1987 glVertex3f(vMinBounds[nDim1], 0, vMinBounds[nDim2] - 6.0f / m_fScale);
1988 glVertex3f(vMinBounds[nDim1], 0, vMinBounds[nDim2] - 10.0f / m_fScale);
1990 glVertex3f(vMinBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale);
1991 glVertex3f(vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale);
1993 glVertex3f(vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 6.0f / m_fScale);
1994 glVertex3f(vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale);
1997 glVertex3f(vMaxBounds[nDim1] + 6.0f / m_fScale, 0,vMinBounds[nDim2]);
1998 glVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMinBounds[nDim2]);
2000 glVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMinBounds[nDim2]);
2001 glVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMaxBounds[nDim2]);
2003 glVertex3f(vMaxBounds[nDim1] + 6.0f / m_fScale, 0,vMaxBounds[nDim2]);
2004 glVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMaxBounds[nDim2]);
2008 glRasterPos3f (Betwixt(vMinBounds[nDim1], vMaxBounds[nDim1]), 0, vMinBounds[nDim2] - 20.0f / m_fScale);
2009 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
2010 GlobalOpenGL().drawString(dimensions.c_str());
2013 glRasterPos3f (vMaxBounds[nDim1] + 16.0f / m_fScale, 0, Betwixt(vMinBounds[nDim2], vMaxBounds[nDim2]));
2014 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
2015 GlobalOpenGL().drawString(dimensions.c_str());
2018 glRasterPos3f (vMinBounds[nDim1] + 4, 0, vMaxBounds[nDim2] + 8 / m_fScale);
2019 dimensions << "(" << g_pOrgStrings[1][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[1][1] << vMaxBounds[nDim2] << ")";
2020 GlobalOpenGL().drawString(dimensions.c_str());
2026 glVertex3f(0, vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale);
2027 glVertex3f(0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale);
2029 glVertex3f(0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale);
2030 glVertex3f(0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale);
2032 glVertex3f(0, vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale);
2033 glVertex3f(0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale);
2036 glVertex3f(0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2]);
2037 glVertex3f(0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2]);
2039 glVertex3f(0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2]);
2040 glVertex3f(0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2]);
2042 glVertex3f(0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2]);
2043 glVertex3f(0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2]);
2047 glRasterPos3f (0, Betwixt(vMinBounds[nDim1], vMaxBounds[nDim1]), vMinBounds[nDim2] - 20.0f / m_fScale);
2048 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
2049 GlobalOpenGL().drawString(dimensions.c_str());
2052 glRasterPos3f (0, vMaxBounds[nDim1] + 16.0f / m_fScale, Betwixt(vMinBounds[nDim2], vMaxBounds[nDim2]));
2053 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
2054 GlobalOpenGL().drawString(dimensions.c_str());
2057 glRasterPos3f (0, vMinBounds[nDim1] + 4.0f, vMaxBounds[nDim2] + 8 / m_fScale);
2058 dimensions << "(" << g_pOrgStrings[2][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[2][1] << vMaxBounds[nDim2] << ")";
2059 GlobalOpenGL().drawString(dimensions.c_str());
2063 class XYRenderer: public Renderer
2072 unsigned int m_highlight;
2076 XYRenderer(RenderStateFlags globalstate, Shader* selected) :
2077 m_globalstate(globalstate),
2078 m_state_selected(selected)
2080 ASSERT_NOTNULL(selected);
2081 m_state_stack.push_back(state_type());
2084 void SetState(Shader* state, EStyle style)
2086 ASSERT_NOTNULL(state);
2087 if(style == eWireframeOnly)
2088 m_state_stack.back().m_state = state;
2090 const EStyle getStyle() const
2092 return eWireframeOnly;
2096 m_state_stack.push_back(m_state_stack.back());
2100 ASSERT_MESSAGE(!m_state_stack.empty(), "popping empty stack");
2101 m_state_stack.pop_back();
2103 void Highlight(EHighlightMode mode, bool bEnable = true)
2106 ? m_state_stack.back().m_highlight |= mode
2107 : m_state_stack.back().m_highlight &= ~mode;
2109 void addRenderable(const OpenGLRenderable& renderable, const Matrix4& localToWorld)
2111 if(m_state_stack.back().m_highlight & ePrimitive)
2113 m_state_selected->addRenderable(renderable, localToWorld);
2117 m_state_stack.back().m_state->addRenderable(renderable, localToWorld);
2121 void render(const Matrix4& modelview, const Matrix4& projection)
2123 GlobalShaderCache().render(m_globalstate, modelview, projection);
2126 std::vector<state_type> m_state_stack;
2127 RenderStateFlags m_globalstate;
2128 Shader* m_state_selected;
2131 void XYWnd::updateProjection()
2133 m_projection[0] = 1.0f / static_cast<float>(m_nWidth / 2);
2134 m_projection[5] = 1.0f / static_cast<float>(m_nHeight / 2);
2135 m_projection[10] = 1.0f / (g_MaxWorldCoord * m_fScale);
2137 m_projection[12] = 0.0f;
2138 m_projection[13] = 0.0f;
2139 m_projection[14] = -1.0f;
2151 m_projection[11] = 0.0f;
2153 m_projection[15] = 1.0f;
2155 m_view.Construct(m_projection, m_modelview, m_nWidth, m_nHeight);
2158 // note: modelview matrix must have a uniform scale, otherwise strange things happen when rendering the rotation manipulator.
2159 void XYWnd::updateModelview()
2161 int nDim1 = (m_viewType == YZ) ? 1 : 0;
2162 int nDim2 = (m_viewType == XY) ? 1 : 2;
2165 m_modelview[12] = -m_vOrigin[nDim1] * m_fScale;
2166 m_modelview[13] = -m_vOrigin[nDim2] * m_fScale;
2167 m_modelview[14] = g_MaxWorldCoord * m_fScale;
2173 m_modelview[0] = m_fScale;
2178 m_modelview[5] = m_fScale;
2183 m_modelview[10] = -m_fScale;
2186 m_modelview[0] = m_fScale;
2192 m_modelview[6] = m_fScale;
2195 m_modelview[9] = m_fScale;
2196 m_modelview[10] = 0;
2201 m_modelview[2] = -m_fScale;
2203 m_modelview[4] = m_fScale;
2208 m_modelview[9] = m_fScale;
2209 m_modelview[10] = 0;
2213 m_modelview[3] = m_modelview[7] = m_modelview[11] = 0;
2214 m_modelview[15] = 1;
2216 m_view.Construct(m_projection, m_modelview, m_nWidth, m_nHeight);
2225 //#define DBG_SCENEDUMP
2227 void XYWnd::XY_Draw()
2232 glViewport(0, 0, m_nWidth, m_nHeight);
2233 glClearColor (g_xywindow_globals.color_gridback[0],
2234 g_xywindow_globals.color_gridback[1],
2235 g_xywindow_globals.color_gridback[2],0);
2237 glClear(GL_COLOR_BUFFER_BIT);
2243 glMatrixMode(GL_PROJECTION);
2244 glLoadMatrixf(reinterpret_cast<const float*>(&m_projection));
2246 glMatrixMode(GL_MODELVIEW);
2248 glScalef(m_fScale, m_fScale, 1);
2249 int nDim1 = (m_viewType == YZ) ? 1 : 0;
2250 int nDim2 = (m_viewType == XY) ? 1 : 2;
2251 glTranslatef(-m_vOrigin[nDim1], -m_vOrigin[nDim2], 0);
2253 glDisable (GL_LINE_STIPPLE);
2255 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
2256 glDisableClientState(GL_NORMAL_ARRAY);
2257 glDisableClientState(GL_COLOR_ARRAY);
2258 glDisable(GL_TEXTURE_2D);
2259 glDisable(GL_LIGHTING);
2260 glDisable(GL_COLOR_MATERIAL);
2261 glDisable(GL_DEPTH_TEST);
2264 if ( g_xywindow_globals_private.show_blocks)
2267 glLoadMatrixf(reinterpret_cast<const float*>(&m_modelview));
2269 unsigned int globalstate = RENDER_COLOURARRAY | RENDER_COLOURWRITE | RENDER_POLYGONSMOOTH | RENDER_LINESMOOTH;
2270 if(!g_xywindow_globals.m_bNoStipple)
2272 globalstate |= RENDER_LINESTIPPLE;
2276 XYRenderer renderer(globalstate, m_state_selected);
2278 Scene_Render(renderer, m_view);
2280 GlobalOpenGL_debugAssertNoErrors();
2281 renderer.render(m_modelview, m_projection);
2282 GlobalOpenGL_debugAssertNoErrors();
2285 glDepthMask(GL_FALSE);
2287 GlobalOpenGL_debugAssertNoErrors();
2289 glLoadMatrixf(reinterpret_cast<const float*>(&m_modelview));
2291 GlobalOpenGL_debugAssertNoErrors();
2292 glDisable(GL_LINE_STIPPLE);
2293 GlobalOpenGL_debugAssertNoErrors();
2295 GlobalOpenGL_debugAssertNoErrors();
2296 if(GlobalOpenGL().GL_1_3())
2298 glActiveTexture(GL_TEXTURE0);
2299 glClientActiveTexture(GL_TEXTURE0);
2301 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
2302 GlobalOpenGL_debugAssertNoErrors();
2303 glDisableClientState(GL_NORMAL_ARRAY);
2304 GlobalOpenGL_debugAssertNoErrors();
2305 glDisableClientState(GL_COLOR_ARRAY);
2306 GlobalOpenGL_debugAssertNoErrors();
2307 glDisable(GL_TEXTURE_2D);
2308 GlobalOpenGL_debugAssertNoErrors();
2309 glDisable(GL_LIGHTING);
2310 GlobalOpenGL_debugAssertNoErrors();
2311 glDisable(GL_COLOR_MATERIAL);
2312 GlobalOpenGL_debugAssertNoErrors();
2314 GlobalOpenGL_debugAssertNoErrors();
2318 if(g_xywindow_globals_private.m_bSizePaint && GlobalSelectionSystem().countSelected() != 0)
2321 Select_GetBounds(min, max);
2322 PaintSizeInfo(nDim1, nDim2, min, max);
2327 glColor4f(0.2f, 0.9f, 0.2f, 0.8f);
2329 if (m_viewType == XY)
2331 glVertex2f(2.0f * g_MinWorldCoord, m_mousePosition[1]);
2332 glVertex2f(2.0f * g_MaxWorldCoord, m_mousePosition[1]);
2333 glVertex2f(m_mousePosition[0], 2.0f * g_MinWorldCoord);
2334 glVertex2f(m_mousePosition[0], 2.0f * g_MaxWorldCoord);
2336 else if (m_viewType == YZ)
2338 glVertex3f(m_mousePosition[0], 2.0f * g_MinWorldCoord, m_mousePosition[2]);
2339 glVertex3f(m_mousePosition[0], 2.0f * g_MaxWorldCoord, m_mousePosition[2]);
2340 glVertex3f(m_mousePosition[0], m_mousePosition[1], 2.0f * g_MinWorldCoord);
2341 glVertex3f(m_mousePosition[0], m_mousePosition[1], 2.0f * g_MaxWorldCoord);
2345 glVertex3f (2.0f * g_MinWorldCoord, m_mousePosition[1], m_mousePosition[2]);
2346 glVertex3f (2.0f * g_MaxWorldCoord, m_mousePosition[1], m_mousePosition[2]);
2347 glVertex3f(m_mousePosition[0], m_mousePosition[1], 2.0f * g_MinWorldCoord);
2348 glVertex3f(m_mousePosition[0], m_mousePosition[1], 2.0f * g_MaxWorldCoord);
2355 GlobalClipPoints_Draw(m_fScale);
2358 GlobalOpenGL_debugAssertNoErrors();
2362 glScalef(m_fScale, m_fScale, 1);
2363 glTranslatef(-m_vOrigin[nDim1], -m_vOrigin[nDim2], 0);
2365 DrawCameraIcon (Camera_getOrigin(*g_pParentWnd->GetCamWnd()), Camera_getAngles(*g_pParentWnd->GetCamWnd()));
2367 Feedback_draw2D( m_viewType );
2369 if (g_xywindow_globals_private.show_outline)
2373 glMatrixMode (GL_PROJECTION);
2375 glOrtho (0, m_nWidth, 0, m_nHeight, 0, 1);
2377 glMatrixMode (GL_MODELVIEW);
2380 // four view mode doesn't colorize
2381 if (g_pParentWnd->CurrentStyle() == MainFrame::eSplit)
2382 glColor3fv(vector3_to_array(g_xywindow_globals.color_viewname));
2388 glColor3fv(vector3_to_array(g_xywindow_globals.AxisColorX));
2391 glColor3fv(vector3_to_array(g_xywindow_globals.AxisColorY));
2394 glColor3fv(vector3_to_array(g_xywindow_globals.AxisColorZ));
2398 glBegin (GL_LINE_LOOP);
2400 glVertex2i (m_nWidth-1, 0);
2401 glVertex2i (m_nWidth-1, m_nHeight-1);
2402 glVertex2i (0, m_nHeight-1);
2407 GlobalOpenGL_debugAssertNoErrors();
2412 void XYWnd_MouseToPoint(XYWnd* xywnd, int x, int y, Vector3& point)
2414 xywnd->XY_ToPoint(x, y, point);
2415 xywnd->XY_SnapToGrid(point);
2417 int nDim = (xywnd->GetViewType() == XY) ? 2 : (xywnd->GetViewType() == YZ) ? 0 : 1;
2418 float fWorkMid = float_mid(Select_getWorkZone().d_work_min[nDim], Select_getWorkZone().d_work_max[nDim]);
2419 point[nDim] = float_snapped(fWorkMid, GetGridSize());
2422 void XYWnd::OnEntityCreate (const char* item)
2424 StringOutputStream command;
2425 command << "entityCreate -class " << item;
2426 UndoableCommand undo(command.c_str());
2428 XYWnd_MouseToPoint(this, m_entityCreate_x, m_entityCreate_y, point);
2429 Entity_createFromSelection(item, point);
2434 void GetFocusPosition(Vector3& position)
2436 if(GlobalSelectionSystem().countSelected() != 0)
2438 Select_GetMid(position);
2442 position = Camera_getOrigin(*g_pParentWnd->GetCamWnd());
2446 void XYWnd_Focus(XYWnd* xywnd)
2449 GetFocusPosition(position);
2450 xywnd->PositionView(position);
2453 void XY_Split_Focus()
2456 GetFocusPosition(position);
2457 g_pParentWnd->GetXYWnd()->PositionView(position);
2458 g_pParentWnd->GetXZWnd()->PositionView(position);
2459 g_pParentWnd->GetYZWnd()->PositionView(position);
2464 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2470 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2471 xywnd->SetViewType(XY);
2477 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2478 xywnd->SetViewType(XZ);
2484 g_pParentWnd->GetXYWnd()->SetViewType(YZ);
2485 XYWnd_Focus(g_pParentWnd->GetXYWnd());
2490 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2491 if (xywnd->GetViewType() == XY)
2492 xywnd->SetViewType(XZ);
2493 else if (xywnd->GetViewType() == XZ)
2494 xywnd->SetViewType(YZ);
2496 xywnd->SetViewType(XY);
2502 if (g_pParentWnd->GetXYWnd())
2503 g_pParentWnd->GetXYWnd()->SetScale(1);
2504 if (g_pParentWnd->GetXZWnd())
2505 g_pParentWnd->GetXZWnd()->SetScale(1);
2506 if (g_pParentWnd->GetYZWnd())
2507 g_pParentWnd->GetYZWnd()->SetScale(1);
2512 XYWnd_ZoomIn(g_pParentWnd->ActiveXY());
2515 // NOTE: the zoom out factor is 4/5, we could think about customizing it
2516 // we don't go below a zoom factor corresponding to 10% of the max world size
2517 // (this has to be computed against the window size)
2520 XYWnd_ZoomOut(g_pParentWnd->ActiveXY());
2525 void ToggleShowCrosshair()
2528 XY_UpdateAllWindows();
2531 void ToggleShowSizeInfo()
2533 g_xywindow_globals_private.m_bSizePaint = !g_xywindow_globals_private.m_bSizePaint;
2534 XY_UpdateAllWindows();
2537 void ToggleShowGrid()
2539 g_xywindow_globals_private.d_showgrid = !g_xywindow_globals_private.d_showgrid;
2540 XY_UpdateAllWindows();
2543 ToggleShown g_xy_top_shown(true);
2545 void XY_Top_Shown_Construct(GtkWindow* parent)
2547 g_xy_top_shown.connect(GTK_WIDGET(parent));
2550 ToggleShown g_yz_side_shown(false);
2552 void YZ_Side_Shown_Construct(GtkWindow* parent)
2554 g_yz_side_shown.connect(GTK_WIDGET(parent));
2557 ToggleShown g_xz_front_shown(false);
2559 void XZ_Front_Shown_Construct(GtkWindow* parent)
2561 g_xz_front_shown.connect(GTK_WIDGET(parent));
2565 class EntityClassMenu : public ModuleObserver
2567 std::size_t m_unrealised;
2569 EntityClassMenu() : m_unrealised(1)
2574 if(--m_unrealised == 0)
2580 if(++m_unrealised == 1)
2582 if(XYWnd::m_mnuDrop != 0)
2584 gtk_widget_destroy(GTK_WIDGET(XYWnd::m_mnuDrop));
2585 XYWnd::m_mnuDrop = 0;
2591 EntityClassMenu g_EntityClassMenu;
2596 void ShowNamesToggle()
2598 GlobalEntityCreator().setShowNames(!GlobalEntityCreator().getShowNames());
2599 XY_UpdateAllWindows();
2601 typedef FreeCaller<ShowNamesToggle> ShowNamesToggleCaller;
2602 void ShowNamesExport(const BoolImportCallback& importer)
2604 importer(GlobalEntityCreator().getShowNames());
2606 typedef FreeCaller1<const BoolImportCallback&, ShowNamesExport> ShowNamesExportCaller;
2608 void ShowAnglesToggle()
2610 GlobalEntityCreator().setShowAngles(!GlobalEntityCreator().getShowAngles());
2611 XY_UpdateAllWindows();
2613 typedef FreeCaller<ShowAnglesToggle> ShowAnglesToggleCaller;
2614 void ShowAnglesExport(const BoolImportCallback& importer)
2616 importer(GlobalEntityCreator().getShowAngles());
2618 typedef FreeCaller1<const BoolImportCallback&, ShowAnglesExport> ShowAnglesExportCaller;
2620 void ShowBlocksToggle()
2622 g_xywindow_globals_private.show_blocks ^= 1;
2623 XY_UpdateAllWindows();
2625 typedef FreeCaller<ShowBlocksToggle> ShowBlocksToggleCaller;
2626 void ShowBlocksExport(const BoolImportCallback& importer)
2628 importer(g_xywindow_globals_private.show_blocks);
2630 typedef FreeCaller1<const BoolImportCallback&, ShowBlocksExport> ShowBlocksExportCaller;
2632 void ShowCoordinatesToggle()
2634 g_xywindow_globals_private.show_coordinates ^= 1;
2635 XY_UpdateAllWindows();
2637 typedef FreeCaller<ShowCoordinatesToggle> ShowCoordinatesToggleCaller;
2638 void ShowCoordinatesExport(const BoolImportCallback& importer)
2640 importer(g_xywindow_globals_private.show_coordinates);
2642 typedef FreeCaller1<const BoolImportCallback&, ShowCoordinatesExport> ShowCoordinatesExportCaller;
2644 void ShowOutlineToggle()
2646 g_xywindow_globals_private.show_outline ^= 1;
2647 XY_UpdateAllWindows();
2649 typedef FreeCaller<ShowOutlineToggle> ShowOutlineToggleCaller;
2650 void ShowOutlineExport(const BoolImportCallback& importer)
2652 importer(g_xywindow_globals_private.show_outline);
2654 typedef FreeCaller1<const BoolImportCallback&, ShowOutlineExport> ShowOutlineExportCaller;
2656 void ShowAxesToggle()
2658 g_xywindow_globals_private.show_axis ^= 1;
2659 XY_UpdateAllWindows();
2661 typedef FreeCaller<ShowAxesToggle> ShowAxesToggleCaller;
2662 void ShowAxesExport(const BoolImportCallback& importer)
2664 importer(g_xywindow_globals_private.show_axis);
2666 typedef FreeCaller1<const BoolImportCallback&, ShowAxesExport> ShowAxesExportCaller;
2668 void ShowWorkzoneToggle()
2670 g_xywindow_globals_private.d_show_work ^= 1;
2671 XY_UpdateAllWindows();
2673 typedef FreeCaller<ShowWorkzoneToggle> ShowWorkzoneToggleCaller;
2674 void ShowWorkzoneExport(const BoolImportCallback& importer)
2676 importer(g_xywindow_globals_private.d_show_work);
2678 typedef FreeCaller1<const BoolImportCallback&, ShowWorkzoneExport> ShowWorkzoneExportCaller;
2680 ShowNamesExportCaller g_show_names_caller;
2681 BoolExportCallback g_show_names_callback(g_show_names_caller);
2682 ToggleItem g_show_names(g_show_names_callback);
2684 ShowAnglesExportCaller g_show_angles_caller;
2685 BoolExportCallback g_show_angles_callback(g_show_angles_caller);
2686 ToggleItem g_show_angles(g_show_angles_callback);
2688 ShowBlocksExportCaller g_show_blocks_caller;
2689 BoolExportCallback g_show_blocks_callback(g_show_blocks_caller);
2690 ToggleItem g_show_blocks(g_show_blocks_callback);
2692 ShowCoordinatesExportCaller g_show_coordinates_caller;
2693 BoolExportCallback g_show_coordinates_callback(g_show_coordinates_caller);
2694 ToggleItem g_show_coordinates(g_show_coordinates_callback);
2696 ShowOutlineExportCaller g_show_outline_caller;
2697 BoolExportCallback g_show_outline_callback(g_show_outline_caller);
2698 ToggleItem g_show_outline(g_show_outline_callback);
2700 ShowAxesExportCaller g_show_axes_caller;
2701 BoolExportCallback g_show_axes_callback(g_show_axes_caller);
2702 ToggleItem g_show_axes(g_show_axes_callback);
2704 ShowWorkzoneExportCaller g_show_workzone_caller;
2705 BoolExportCallback g_show_workzone_callback(g_show_workzone_caller);
2706 ToggleItem g_show_workzone(g_show_workzone_callback);
2708 void XYShow_registerCommands()
2710 GlobalToggles_insert("ShowAngles", ShowAnglesToggleCaller(), ToggleItem::AddCallbackCaller(g_show_angles));
2711 GlobalToggles_insert("ShowNames", ShowNamesToggleCaller(), ToggleItem::AddCallbackCaller(g_show_names));
2712 GlobalToggles_insert("ShowBlocks", ShowBlocksToggleCaller(), ToggleItem::AddCallbackCaller(g_show_blocks));
2713 GlobalToggles_insert("ShowCoordinates", ShowCoordinatesToggleCaller(), ToggleItem::AddCallbackCaller(g_show_coordinates));
2714 GlobalToggles_insert("ShowWindowOutline", ShowOutlineToggleCaller(), ToggleItem::AddCallbackCaller(g_show_outline));
2715 GlobalToggles_insert("ShowAxes", ShowAxesToggleCaller(), ToggleItem::AddCallbackCaller(g_show_axes));
2716 GlobalToggles_insert("ShowWorkzone", ShowWorkzoneToggleCaller(), ToggleItem::AddCallbackCaller(g_show_workzone));
2719 void XYWnd_registerShortcuts()
2721 command_connect_accelerator("ToggleCrosshairs");
2722 command_connect_accelerator("ToggleSizePaint");
2727 void Orthographic_constructPreferences(PreferencesPage& page)
2729 page.appendCheckBox("", "Solid selection boxes", g_xywindow_globals.m_bNoStipple);
2730 page.appendCheckBox("", "Display size info", g_xywindow_globals_private.m_bSizePaint);
2731 page.appendCheckBox("", "Chase mouse during drags", g_xywindow_globals_private.m_bChaseMouse);
2732 page.appendCheckBox("", "Update views on camera move", g_xywindow_globals_private.m_bCamXYUpdate);
2734 void Orthographic_constructPage(PreferenceGroup& group)
2736 PreferencesPage page(group.createPage("Orthographic", "Orthographic View Preferences"));
2737 Orthographic_constructPreferences(page);
2739 void Orthographic_registerPreferencesPage()
2741 PreferencesDialog_addSettingsPage(FreeCaller1<PreferenceGroup&, Orthographic_constructPage>());
2744 void Clipper_constructPreferences(PreferencesPage& page)
2746 page.appendCheckBox("", "Clipper tool uses caulk", g_clip_useCaulk);
2748 void Clipper_constructPage(PreferenceGroup& group)
2750 PreferencesPage page(group.createPage("Clipper", "Clipper Tool Settings"));
2751 Clipper_constructPreferences(page);
2753 void Clipper_registerPreferencesPage()
2755 PreferencesDialog_addSettingsPage(FreeCaller1<PreferenceGroup&, Clipper_constructPage>());
2759 #include "preferencesystem.h"
2760 #include "stringio.h"
2765 void ToggleShown_importBool(ToggleShown& self, bool value)
2769 typedef ReferenceCaller1<ToggleShown, bool, ToggleShown_importBool> ToggleShownImportBoolCaller;
2770 void ToggleShown_exportBool(const ToggleShown& self, const BoolImportCallback& importer)
2772 importer(self.active());
2774 typedef ConstReferenceCaller1<ToggleShown, const BoolImportCallback&, ToggleShown_exportBool> ToggleShownExportBoolCaller;
2777 void XYWindow_Construct()
2779 GlobalCommands_insert("ToggleCrosshairs", FreeCaller<ToggleShowCrosshair>(), Accelerator('X', (GdkModifierType)GDK_SHIFT_MASK));
2780 GlobalCommands_insert("ToggleSizePaint", FreeCaller<ToggleShowSizeInfo>(), Accelerator('J'));
2781 GlobalCommands_insert("ToggleGrid", FreeCaller<ToggleShowGrid>(), Accelerator('0'));
2783 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)));
2784 GlobalToggles_insert("ToggleSideView", ToggleShown::ToggleCaller(g_yz_side_shown), ToggleItem::AddCallbackCaller(g_yz_side_shown.m_item));
2785 GlobalToggles_insert("ToggleFrontView", ToggleShown::ToggleCaller(g_xz_front_shown), ToggleItem::AddCallbackCaller(g_xz_front_shown.m_item));
2786 GlobalCommands_insert("NextView", FreeCaller<XY_Next>(), Accelerator(GDK_Tab, (GdkModifierType)GDK_CONTROL_MASK));
2787 GlobalCommands_insert("ZoomIn", FreeCaller<XY_ZoomIn>(), Accelerator(GDK_Delete));
2788 GlobalCommands_insert("ZoomOut", FreeCaller<XY_ZoomOut>(), Accelerator(GDK_Insert));
2789 GlobalCommands_insert("ViewTop", FreeCaller<XY_Top>());
2790 GlobalCommands_insert("ViewSide", FreeCaller<XY_Side>());
2791 GlobalCommands_insert("ViewFront", FreeCaller<XY_Front>());
2792 GlobalCommands_insert("Zoom100", FreeCaller<XY_Zoom100>());
2793 GlobalCommands_insert("CenterXYViews", FreeCaller<XY_Split_Focus>(), Accelerator(GDK_Tab, (GdkModifierType)(GDK_SHIFT_MASK|GDK_CONTROL_MASK)));
2794 GlobalCommands_insert("CenterXYView", FreeCaller<XY_Focus>(), Accelerator(GDK_Tab, (GdkModifierType)(GDK_SHIFT_MASK|GDK_CONTROL_MASK)));
2796 GlobalPreferenceSystem().registerPreference("ClipCaulk", BoolImportStringCaller(g_clip_useCaulk), BoolExportStringCaller(g_clip_useCaulk));
2798 GlobalPreferenceSystem().registerPreference("NewRightClick", BoolImportStringCaller(g_xywindow_globals.m_bRightClick), BoolExportStringCaller(g_xywindow_globals.m_bRightClick));
2799 GlobalPreferenceSystem().registerPreference("ChaseMouse", BoolImportStringCaller(g_xywindow_globals_private.m_bChaseMouse), BoolExportStringCaller(g_xywindow_globals_private.m_bChaseMouse));
2800 GlobalPreferenceSystem().registerPreference("SizePainting", BoolImportStringCaller(g_xywindow_globals_private.m_bSizePaint), BoolExportStringCaller(g_xywindow_globals_private.m_bSizePaint));
2801 GlobalPreferenceSystem().registerPreference("NoStipple", BoolImportStringCaller(g_xywindow_globals.m_bNoStipple), BoolExportStringCaller(g_xywindow_globals.m_bNoStipple));
2802 GlobalPreferenceSystem().registerPreference("SI_ShowCoords", BoolImportStringCaller(g_xywindow_globals_private.show_coordinates), BoolExportStringCaller(g_xywindow_globals_private.show_coordinates));
2803 GlobalPreferenceSystem().registerPreference("SI_ShowOutlines", BoolImportStringCaller(g_xywindow_globals_private.show_outline), BoolExportStringCaller(g_xywindow_globals_private.show_outline));
2804 GlobalPreferenceSystem().registerPreference("SI_ShowAxis", BoolImportStringCaller(g_xywindow_globals_private.show_axis), BoolExportStringCaller(g_xywindow_globals_private.show_axis));
2805 GlobalPreferenceSystem().registerPreference("CamXYUpdate", BoolImportStringCaller(g_xywindow_globals_private.m_bCamXYUpdate), BoolExportStringCaller(g_xywindow_globals_private.m_bCamXYUpdate));
2806 GlobalPreferenceSystem().registerPreference("ShowWorkzone", BoolImportStringCaller(g_xywindow_globals_private.d_show_work), BoolExportStringCaller(g_xywindow_globals_private.d_show_work));
2808 GlobalPreferenceSystem().registerPreference("SI_AxisColors0", Vector3ImportStringCaller(g_xywindow_globals.AxisColorX), Vector3ExportStringCaller(g_xywindow_globals.AxisColorX));
2809 GlobalPreferenceSystem().registerPreference("SI_AxisColors1", Vector3ImportStringCaller(g_xywindow_globals.AxisColorY), Vector3ExportStringCaller(g_xywindow_globals.AxisColorY));
2810 GlobalPreferenceSystem().registerPreference("SI_AxisColors2", Vector3ImportStringCaller(g_xywindow_globals.AxisColorZ), Vector3ExportStringCaller(g_xywindow_globals.AxisColorZ));
2811 GlobalPreferenceSystem().registerPreference("SI_Colors1", Vector3ImportStringCaller(g_xywindow_globals.color_gridback), Vector3ExportStringCaller(g_xywindow_globals.color_gridback));
2812 GlobalPreferenceSystem().registerPreference("SI_Colors2", Vector3ImportStringCaller(g_xywindow_globals.color_gridminor), Vector3ExportStringCaller(g_xywindow_globals.color_gridminor));
2813 GlobalPreferenceSystem().registerPreference("SI_Colors3", Vector3ImportStringCaller(g_xywindow_globals.color_gridmajor), Vector3ExportStringCaller(g_xywindow_globals.color_gridmajor));
2814 GlobalPreferenceSystem().registerPreference("SI_Colors6", Vector3ImportStringCaller(g_xywindow_globals.color_gridblock), Vector3ExportStringCaller(g_xywindow_globals.color_gridblock));
2815 GlobalPreferenceSystem().registerPreference("SI_Colors7", Vector3ImportStringCaller(g_xywindow_globals.color_gridtext), Vector3ExportStringCaller(g_xywindow_globals.color_gridtext));
2816 GlobalPreferenceSystem().registerPreference("SI_Colors8", Vector3ImportStringCaller(g_xywindow_globals.color_brushes), Vector3ExportStringCaller(g_xywindow_globals.color_brushes));
2817 GlobalPreferenceSystem().registerPreference("SI_Colors9", Vector3ImportStringCaller(g_xywindow_globals.color_selbrushes), Vector3ExportStringCaller(g_xywindow_globals.color_selbrushes));
2818 GlobalPreferenceSystem().registerPreference("SI_Colors10", Vector3ImportStringCaller(g_xywindow_globals.color_clipper), Vector3ExportStringCaller(g_xywindow_globals.color_clipper));
2819 GlobalPreferenceSystem().registerPreference("SI_Colors11", Vector3ImportStringCaller(g_xywindow_globals.color_viewname), Vector3ExportStringCaller(g_xywindow_globals.color_viewname));
2820 GlobalPreferenceSystem().registerPreference("SI_Colors13", Vector3ImportStringCaller(g_xywindow_globals.color_gridminor_alt), Vector3ExportStringCaller(g_xywindow_globals.color_gridminor_alt));
2821 GlobalPreferenceSystem().registerPreference("SI_Colors14", Vector3ImportStringCaller(g_xywindow_globals.color_gridmajor_alt), Vector3ExportStringCaller(g_xywindow_globals.color_gridmajor_alt));
2824 GlobalPreferenceSystem().registerPreference("XZVIS", makeBoolStringImportCallback(ToggleShownImportBoolCaller(g_xz_front_shown)), makeBoolStringExportCallback(ToggleShownExportBoolCaller(g_xz_front_shown)));
2825 GlobalPreferenceSystem().registerPreference("YZVIS", makeBoolStringImportCallback(ToggleShownImportBoolCaller(g_yz_side_shown)), makeBoolStringExportCallback(ToggleShownExportBoolCaller(g_yz_side_shown)));
2827 Orthographic_registerPreferencesPage();
2828 Clipper_registerPreferencesPage();
2830 XYWnd::captureStates();
2831 GlobalEntityClassManager().attach(g_EntityClassMenu);
2834 void XYWindow_Destroy()
2836 GlobalEntityClassManager().detach(g_EntityClassMenu);
2837 XYWnd::releaseStates();