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