]> git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/xywindow.h
Inject OpenGLBinding instead of using GlobalOpenGL() everywhere
[xonotic/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
39 class SelectionSystemWindowObserver;
40 namespace scene {
41     class Node;
42 }
43
44
45 void FlipClip();
46
47 void SplitClip();
48
49 void Clip();
50
51 void OnClipMode(bool enabled);
52
53 bool ClipMode();
54
55 inline const char *ViewType_getTitle(VIEWTYPE viewtype)
56 {
57     if (viewtype == XY) {
58         return "XY Top";
59     }
60     if (viewtype == XZ) {
61         return "XZ Front";
62     }
63     if (viewtype == YZ) {
64         return "YZ Side";
65     }
66     return "";
67 }
68
69 struct OpenGLBinding;
70
71 class XYWnd {
72 public:
73     OpenGLBinding ≷
74 private:
75     ui::GLArea m_gl_widget;
76     guint m_sizeHandler;
77     guint m_exposeHandler;
78
79     DeferredDraw m_deferredDraw;
80     DeferredMotion m_deferred_motion;
81 public:
82     ui::Window m_parent;
83
84     XYWnd(OpenGLBinding &GL);
85
86     ~XYWnd();
87
88     void queueDraw()
89     {
90         m_deferredDraw.draw();
91     }
92
93     ui::GLArea GetWidget()
94     {
95         return m_gl_widget;
96     }
97
98 public:
99     SelectionSystemWindowObserver *m_window_observer;
100     XORRectangle m_XORRectangle;
101     WindowPositionTracker m_positionTracker;
102
103     static void captureStates();
104
105     static void releaseStates();
106
107     void PositionView(const Vector3 &position);
108
109     const Vector3 &GetOrigin();
110
111     void SetOrigin(const Vector3 &origin);
112
113     void Scroll(int x, int y);
114
115     void XY_Draw();
116
117     void DrawCameraIcon(const Vector3 &origin, const Vector3 &angles);
118
119     void XY_DrawBlockGrid();
120
121     void XY_DrawAxis();
122
123     void XY_DrawGrid();
124
125     void XY_DrawBackground();
126
127     void XY_LoadBackgroundImage(const char *name);
128
129     void XY_DisableBackground();
130
131     void XY_MouseUp(int x, int y, unsigned int buttons);
132
133     void XY_MouseDown(int x, int y, unsigned int buttons);
134
135     void XY_MouseMoved(int x, int y, unsigned int buttons);
136
137     void NewBrushDrag_Begin(int x, int y);
138
139     void NewBrushDrag(int x, int y);
140
141     void NewBrushDrag_End(int x, int y);
142
143     void XY_ToPoint(int x, int y, Vector3 &point);
144
145     void XY_SnapToGrid(Vector3 &point);
146
147     void Move_Begin();
148
149     void Move_End();
150
151     bool m_move_started;
152     guint m_move_focusOut;
153
154     void Zoom_Begin();
155
156     void Zoom_End();
157
158     bool m_zoom_started;
159     guint m_zoom_focusOut;
160
161     void SetActive(bool b)
162     {
163         m_bActive = b;
164     };
165
166     bool Active()
167     {
168         return m_bActive;
169     };
170
171     void Clipper_OnLButtonDown(int x, int y);
172
173     void Clipper_OnLButtonUp(int x, int y);
174
175     void Clipper_OnMouseMoved(int x, int y);
176
177     void Clipper_Crosshair_OnMouseMoved(int x, int y);
178
179     void DropClipPoint(int pointx, int pointy);
180
181     void SetViewType(VIEWTYPE n);
182
183     bool m_bActive;
184
185     static ui::Menu m_mnuDrop;
186
187     int m_chasemouse_current_x, m_chasemouse_current_y;
188     int m_chasemouse_delta_x, m_chasemouse_delta_y;
189
190
191     guint m_chasemouse_handler;
192
193     void ChaseMouse();
194
195     bool chaseMouseMotion(int pointx, int pointy);
196
197     void updateModelview();
198
199     void updateProjection();
200
201     Matrix4 m_projection;
202     Matrix4 m_modelview;
203
204     int m_nWidth;
205     int m_nHeight;
206 // background image stuff
207     qtexture_t *m_tex;
208     bool m_backgroundActivated;
209     float m_alpha;   // vertex alpha
210     float m_xmin, m_ymin, m_xmax, m_ymax;
211 private:
212     float m_fScale;
213     Vector3 m_vOrigin;
214
215
216     View m_view;
217     static Shader *m_state_selected;
218
219     int m_ptCursorX, m_ptCursorY;
220
221     unsigned int m_buttonstate;
222
223     int m_nNewBrushPressx;
224     int m_nNewBrushPressy;
225     scene::Node *m_NewBrushDrag;
226     bool m_bNewBrushDrag;
227
228     Vector3 m_mousePosition;
229
230     VIEWTYPE m_viewType;
231
232     void OriginalButtonUp(guint32 nFlags, int point, int pointy);
233
234     void OriginalButtonDown(guint32 nFlags, int point, int pointy);
235
236     void OnContextMenu();
237
238     void PaintSizeInfo(int nDim1, int nDim2, Vector3 &vMinBounds, Vector3 &vMaxBounds);
239
240     int m_entityCreate_x, m_entityCreate_y;
241     bool m_entityCreate;
242
243 public:
244     void ButtonState_onMouseDown(unsigned int buttons)
245     {
246         m_buttonstate |= buttons;
247     }
248
249     void ButtonState_onMouseUp(unsigned int buttons)
250     {
251         m_buttonstate &= ~buttons;
252     }
253
254     unsigned int getButtonState() const
255     {
256         return m_buttonstate;
257     }
258
259     void EntityCreate_MouseDown(int x, int y);
260
261     void EntityCreate_MouseMove(int x, int y);
262
263     void EntityCreate_MouseUp(int x, int y);
264
265     void OnEntityCreate(const char *item);
266
267     VIEWTYPE GetViewType()
268     {
269         return m_viewType;
270     }
271
272     void SetScale(float f);
273
274     float Scale()
275     {
276         return m_fScale;
277     }
278
279     int Width()
280     {
281         return m_nWidth;
282     }
283
284     int Height()
285     {
286         return m_nHeight;
287     }
288
289     Signal0 onDestroyed;
290     Signal3<const WindowVector &, ButtonIdentifier, ModifierFlags> onMouseDown;
291
292     void mouseDown(const WindowVector &position, ButtonIdentifier button, ModifierFlags modifiers);
293
294     typedef Member<XYWnd, void(const WindowVector &, ButtonIdentifier,
295                                ModifierFlags), &XYWnd::mouseDown> MouseDownCaller;
296 };
297
298 inline void XYWnd_Update(XYWnd &xywnd)
299 {
300     xywnd.queueDraw();
301 }
302
303
304 struct xywindow_globals_t {
305     Vector3 color_gridback;
306     Vector3 color_gridminor;
307     Vector3 color_gridmajor;
308     Vector3 color_gridblock;
309     Vector3 color_gridtext;
310     Vector3 color_brushes;
311     Vector3 color_selbrushes;
312     Vector3 color_clipper;
313     Vector3 color_viewname;
314     Vector3 color_gridminor_alt;
315     Vector3 color_gridmajor_alt;
316     Vector3 AxisColorX;
317     Vector3 AxisColorY;
318     Vector3 AxisColorZ;
319
320     bool m_bRightClick;
321     bool m_bNoStipple;
322
323     xywindow_globals_t() :
324             color_gridback(1.f, 1.f, 1.f),
325             color_gridminor(0.75f, 0.75f, 0.75f),
326             color_gridmajor(0.5f, 0.5f, 0.5f),
327             color_gridblock(0.f, 0.f, 1.f),
328             color_gridtext(0.f, 0.f, 0.f),
329             color_brushes(0.f, 0.f, 0.f),
330             color_selbrushes(1.f, 0.f, 0.f),
331             color_clipper(0.f, 0.f, 1.f),
332             color_viewname(0.5f, 0.f, 0.75f),
333             color_gridminor_alt(0.f, 0.f, 0.f),
334             color_gridmajor_alt(0.f, 0.f, 0.f),
335
336             AxisColorX(1.f, 0.f, 0.f),
337             AxisColorY(0.f, 1.f, 0.f),
338             AxisColorZ(0.f, 0.f, 1.f),
339             m_bRightClick(true),
340             m_bNoStipple(false)
341     {
342     }
343
344 };
345
346 extern xywindow_globals_t g_xywindow_globals;
347
348
349 VIEWTYPE GlobalXYWnd_getCurrentViewType();
350
351 void XY_Top_Shown_Construct(ui::Window parent);
352
353 void YZ_Side_Shown_Construct(ui::Window parent);
354
355 void XZ_Front_Shown_Construct(ui::Window parent);
356
357 void XYWindow_Construct();
358
359 void XYWindow_Destroy();
360
361 void WXY_Print();
362
363 void WXY_BackgroundSelect();
364
365 void XYShow_registerCommands();
366
367 void XYWnd_registerShortcuts();
368
369 #endif