]> icculus.org git repositories - divverent/netradiant.git/blob - radiant/xywindow.h
a Q3 map origin to origin brush converter to fix maps that this q3map2 no longer...
[divverent/netradiant.git] / radiant / xywindow.h
1 /*
2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
4
5 This file is part of GtkRadiant.
6
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.
11
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.
16
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
20 */
21
22 #if !defined(INCLUDED_XYWINDOW_H)
23 #define INCLUDED_XYWINDOW_H
24
25 #include "math/matrix.h"
26 #include "signal/signal.h"
27
28 #include "gtkutil/cursor.h"
29 #include "gtkutil/window.h"
30 #include "gtkutil/xorrectangle.h"
31 #include "view.h"
32 #include "map.h"
33 #include "texturelib.h"
34
35 #include "qerplugin.h"
36
37 class Shader;
38 class SelectionSystemWindowObserver;
39 namespace scene
40 {
41   class Node;
42 }
43 typedef struct _GtkWindow GtkWindow;
44 typedef struct _GtkMenu GtkMenu;
45
46
47 void FlipClip();
48 void SplitClip();
49 void Clip();
50 void OnClipMode(bool enabled);
51 bool ClipMode();
52
53 inline const char* ViewType_getTitle(VIEWTYPE viewtype)
54 {
55   if(viewtype == XY)
56   {
57     return "XY Top";
58   }
59   if(viewtype == XZ)
60   {
61     return "XZ Front";
62   }
63   if(viewtype == YZ)
64   {
65     return "YZ Side";
66   }
67   return "";
68 }
69
70 class XYWnd
71 {
72   GtkWidget* m_gl_widget;
73   guint m_sizeHandler;
74   guint m_exposeHandler;
75
76   DeferredDraw m_deferredDraw;
77   DeferredMotion m_deferred_motion;
78 public:
79   GtkWindow* m_parent;
80   XYWnd();
81   ~XYWnd();
82
83   void queueDraw()
84   {
85     m_deferredDraw.draw();
86   }
87   GtkWidget* GetWidget()
88   {
89     return m_gl_widget;
90   }
91
92 public:
93   SelectionSystemWindowObserver* m_window_observer;
94   XORRectangle m_XORRectangle;
95   WindowPositionTracker m_positionTracker;
96
97   static void captureStates();
98   static void releaseStates();
99
100   void PositionView(const Vector3& position);
101   const Vector3& GetOrigin();
102   void SetOrigin(const Vector3& origin);
103   void Scroll(int x, int y);
104
105   void XY_Draw();
106   void DrawCameraIcon(const Vector3& origin, const Vector3& angles);
107   void XY_DrawBlockGrid();
108   void XY_DrawAxis();
109   void XY_DrawGrid();
110   void XY_DrawBackground();
111   void XY_LoadBackgroundImage(const char *name);
112   void XY_DisableBackground();
113
114   void XY_MouseUp(int x, int y, unsigned int buttons);
115   void XY_MouseDown(int x, int y, unsigned int buttons);
116   void XY_MouseMoved(int x, int y, unsigned int buttons);
117
118   void NewBrushDrag_Begin(int x, int y);
119   void NewBrushDrag(int x, int y);
120   void NewBrushDrag_End(int x, int y);
121
122   void XY_ToPoint(int x, int y, Vector3& point);
123   void XY_SnapToGrid(Vector3& point);
124
125   void Move_Begin();
126   void Move_End();
127   bool m_move_started;
128   guint m_move_focusOut;
129
130   void Zoom_Begin();
131   void Zoom_End();
132   bool m_zoom_started;
133   guint m_zoom_focusOut;
134
135   void SetActive(bool b)
136   {
137     m_bActive = b;
138   };
139   bool Active()
140   {
141     return m_bActive;
142   };
143
144   void Clipper_OnLButtonDown(int x, int y);
145   void Clipper_OnLButtonUp(int x, int y);
146   void Clipper_OnMouseMoved(int x, int y);
147   void Clipper_Crosshair_OnMouseMoved(int x, int y);
148   void DropClipPoint(int pointx, int pointy);
149
150   void SetViewType(VIEWTYPE n);
151   bool m_bActive;
152
153   static GtkMenu* m_mnuDrop;
154
155   int m_chasemouse_current_x, m_chasemouse_current_y;
156   int m_chasemouse_delta_x, m_chasemouse_delta_y;
157
158
159   guint m_chasemouse_handler;
160   void ChaseMouse();
161   bool chaseMouseMotion(int pointx, int pointy);
162
163   void updateModelview();
164   void updateProjection();
165   Matrix4 m_projection;
166   Matrix4 m_modelview;
167
168   int m_nWidth;
169   int m_nHeight;
170   // background image stuff
171   qtexture_t *m_tex;
172   bool m_backgroundActivated;
173   float m_alpha; // vertex alpha
174   float m_xmin, m_ymin, m_xmax, m_ymax;
175 private:
176   float m_fScale;
177   Vector3 m_vOrigin;
178
179
180   View m_view;
181   static Shader* m_state_selected;
182
183   int m_ptCursorX, m_ptCursorY;
184
185   unsigned int m_buttonstate;
186
187   int m_nNewBrushPressx;
188   int m_nNewBrushPressy;
189   scene::Node* m_NewBrushDrag;
190   bool m_bNewBrushDrag;
191
192   Vector3 m_mousePosition;
193
194   VIEWTYPE m_viewType;
195
196   void OriginalButtonUp(guint32 nFlags, int point, int pointy);
197   void OriginalButtonDown(guint32 nFlags, int point, int pointy);
198
199   void OnContextMenu();
200   void PaintSizeInfo(int nDim1, int nDim2, Vector3& vMinBounds, Vector3& vMaxBounds);
201
202   int m_entityCreate_x, m_entityCreate_y;
203   bool m_entityCreate;
204
205 public:
206   void ButtonState_onMouseDown(unsigned int buttons)
207   {
208     m_buttonstate |= buttons;
209   }
210   void ButtonState_onMouseUp(unsigned int buttons)
211   {
212     m_buttonstate &= ~buttons;
213   }
214   unsigned int getButtonState() const
215   {
216     return m_buttonstate;
217   }
218   void EntityCreate_MouseDown(int x, int y);
219   void EntityCreate_MouseMove(int x, int y);
220   void EntityCreate_MouseUp(int x, int y);
221
222   void OnEntityCreate(const char* item);
223   VIEWTYPE GetViewType()
224   {
225     return m_viewType;
226   }
227   void SetScale(float f);
228   float Scale()
229   {
230     return m_fScale;
231   }
232   int Width()
233   {
234     return m_nWidth;
235   }
236   int Height()
237   {
238     return m_nHeight;
239   }
240
241   Signal0 onDestroyed;
242   Signal3<const WindowVector&, ButtonIdentifier, ModifierFlags> onMouseDown;
243   void mouseDown(const WindowVector& position, ButtonIdentifier button, ModifierFlags modifiers);
244   typedef Member3<XYWnd, const WindowVector&, ButtonIdentifier, ModifierFlags, void, &XYWnd::mouseDown> MouseDownCaller;
245 };
246
247 inline void XYWnd_Update(XYWnd& xywnd)
248 {
249   xywnd.queueDraw();
250 }
251
252
253 struct xywindow_globals_t
254 {
255   Vector3 color_gridback;
256   Vector3 color_gridminor;
257   Vector3 color_gridmajor;
258   Vector3 color_gridblock;
259   Vector3 color_gridtext;
260   Vector3 color_brushes;
261   Vector3 color_selbrushes;
262   Vector3 color_clipper;
263   Vector3 color_viewname;
264   Vector3 color_gridminor_alt;
265   Vector3 color_gridmajor_alt;
266   Vector3 AxisColorX;
267   Vector3 AxisColorY;
268   Vector3 AxisColorZ;
269
270   bool m_bRightClick;
271   bool m_bNoStipple;
272
273   xywindow_globals_t() :
274     color_gridback(1.f, 1.f, 1.f),
275     color_gridminor(0.75f, 0.75f, 0.75f),
276     color_gridmajor(0.5f, 0.5f, 0.5f),
277     color_gridblock(0.f, 0.f, 1.f),
278     color_gridtext(0.f, 0.f, 0.f),
279     color_brushes(0.f, 0.f, 0.f),
280     color_selbrushes(1.f, 0.f, 0.f),
281     color_clipper(0.f, 0.f, 1.f),
282     color_viewname(0.5f, 0.f, 0.75f),
283     color_gridminor_alt(0.f, 0.f, 0.f),
284     color_gridmajor_alt(0.f, 0.f, 0.f),
285
286     AxisColorX(1.f, 0.f, 0.f),
287     AxisColorY(0.f, 1.f, 0.f),
288     AxisColorZ(0.f, 0.f, 1.f),
289     m_bRightClick(true),
290     m_bNoStipple(false)
291   {
292   }
293
294 };
295
296 extern xywindow_globals_t g_xywindow_globals;
297
298
299 VIEWTYPE GlobalXYWnd_getCurrentViewType();
300
301 typedef struct _GtkWindow GtkWindow;
302 void XY_Top_Shown_Construct(GtkWindow* parent);
303 void YZ_Side_Shown_Construct(GtkWindow* parent);
304 void XZ_Front_Shown_Construct(GtkWindow* parent);
305
306 void XYWindow_Construct();
307 void XYWindow_Destroy();
308
309 void WXY_Print();
310 void WXY_BackgroundSelect();
311
312 void XYShow_registerCommands();
313 void XYWnd_registerShortcuts();
314
315 #endif