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