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