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