]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/camwindow.h
uncrustify! now the code is only ugly on the *inside*
[xonotic/netradiant.git] / radiant / camwindow.h
1 /*
2    Copyright (C) 1999-2007 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 #ifndef _CAMWINDOW_H_
23 #define _CAMWINDOW_H_
24
25 class XYWnd;
26
27 #include "glwindow.h"
28
29 class rectangle_t
30 {
31 public:
32 rectangle_t()
33         : x( 0 ), y( 0 ), w( 0 ), h( 0 )
34 {}
35 rectangle_t( float _x, float _y, float _w, float _h )
36         : x( _x ), y( _y ), w( _w ), h( _h )
37 {}
38 float x;
39 float y;
40 float w;
41 float h;
42 };
43
44 class XORRectangle
45 {
46 public:
47 XORRectangle( GtkWidget* widget )
48         : m_widget( widget ), m_gc( NULL )
49 {}
50 ~XORRectangle(){
51         if ( initialised() ) {
52                 gdk_gc_unref( m_gc );
53         }
54 }
55 void set( rectangle_t rectangle ){
56         lazy_init();
57         draw();
58         m_rectangle = rectangle;
59         draw();
60 }
61 private:
62 bool initialised() const {
63         return m_gc != NULL;
64 }
65 void lazy_init(){
66         if ( !initialised() ) {
67                 m_gc = gdk_gc_new( m_widget->window );
68
69                 GdkColor color = { 0, 0xffff, 0xffff, 0xffff, };
70                 GdkColormap* colormap = gdk_window_get_colormap( m_widget->window );
71                 gdk_colormap_alloc_color( colormap, &color, FALSE, TRUE );
72                 gdk_gc_copy( m_gc, m_widget->style->white_gc );
73                 gdk_gc_set_foreground( m_gc, &color );
74                 gdk_gc_set_background( m_gc, &color );
75
76                 gdk_gc_set_function( m_gc, GDK_XOR );
77         }
78 }
79 void draw() const {
80         const int x = (int)m_rectangle.x;
81         const int y = (int)m_rectangle.y;
82         const int w = (int)m_rectangle.w;
83         const int h = (int)m_rectangle.h;
84         gdk_draw_rectangle( m_widget->window, m_gc, TRUE, x, -( h ) - ( y - m_widget->allocation.height ), w, h );
85 }
86
87 rectangle_t m_rectangle;
88
89 GtkWidget* m_widget;
90 GdkGC* m_gc;
91 };
92
93 class CamWnd : public GLWindow
94 {
95 public:
96 void MatchViewAxes( const vec3_t P, const vec3_t vec, int &axis, float &sgn );
97 void ReInitGL();
98 void BenchMark();
99 CamWnd();
100 virtual ~CamWnd();
101 camera_t *Camera(){return &m_Camera; };
102 void Cam_MouseControl( float dtime );
103 void Cam_ChangeFloor( qboolean up );
104 void ToggleFreeMove();
105 bool m_bFreeMove;
106
107 protected:
108 void Cam_Init();
109 void Cam_BuildMatrix();
110 void Cam_PositionDrag();
111 void Cam_KeyControl( float dtime );
112 void Cam_MouseDown( int x, int y, int buttons );
113 void Cam_MouseUp( int x, int y, int buttons );
114 void Cam_MouseMoved( int x, int y, int buttons );
115 void InitCull();
116 qboolean CullBrush( brush_t *b );
117 void Cam_Draw();
118 void Cam_DrawStuff();
119 void Cam_DrawBrushes( int mode );
120 void Cam_DrawBrush( brush_t *b, int mode );
121
122 brush_t* m_TransBrushes[MAX_MAP_BRUSHES];
123 int m_nNumTransBrushes;
124 camera_t m_Camera;
125 int m_nCambuttonstate;
126 int m_ptButtonX;
127 int m_ptCursorX;
128 int m_ptLastCursorX;
129 int m_ptLastCamCursorX;
130 int m_ptButtonY;
131 int m_ptCursorY;
132 int m_ptLastCursorY;
133 int m_ptLastCamCursorY;
134 face_t* m_pSide_select;
135 vec3_t m_vCull1;
136 vec3_t m_vCull2;
137 int m_nCullv1[3];
138 int m_nCullv2[3];
139 bool m_bClipMode;
140 guint m_FocusOutHandler_id;
141
142 void OnCreate();
143 void OnExpose();
144 void OnLButtonDown( guint32 flags, int x, int y );
145 void OnRButtonDown( guint32 flags, int x, int y );
146 void OnMButtonDown( guint32 flags, int x, int y );
147 void OnLButtonUp( guint32 flags, int pointx, int pointy );
148 void OnRButtonUp( guint32 flags, int pointx, int pointy );
149 void OnMButtonUp( guint32 flags, int pointx, int pointy );
150 void OnMouseMove( guint32 flags, int pointx, int pointy );
151 void OnMouseWheel( bool bUp );
152 void OnSize( int cx, int cy );
153
154 protected:
155 void OriginalMouseDown( guint32 nFlags, int pointX, int pointY );
156 void OriginalMouseUp( guint32 nFlags, int pointX, int pointY );
157
158 private:
159 XORRectangle m_XORRectangle;
160
161 // project a point in geometric space into camera space
162 void ProjectCamera( const vec3_t A, vec_t B[2] );
163 };
164
165
166 #endif // _CAMWINDOW_H_