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