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