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