]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/camwindow.h
transfer from internal tree r5311 branches/1.4-gpl
[xonotic/netradiant.git] / radiant / camwindow.h
1 /*\r
2 Copyright (C) 1999-2007 id Software, Inc. and contributors.\r
3 For a list of contributors, see the accompanying CONTRIBUTORS file.\r
4 \r
5 This file is part of GtkRadiant.\r
6 \r
7 GtkRadiant is free software; you can redistribute it and/or modify\r
8 it under the terms of the GNU General Public License as published by\r
9 the Free Software Foundation; either version 2 of the License, or\r
10 (at your option) any later version.\r
11 \r
12 GtkRadiant is distributed in the hope that it will be useful,\r
13 but WITHOUT ANY WARRANTY; without even the implied warranty of\r
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
15 GNU General Public License for more details.\r
16 \r
17 You should have received a copy of the GNU General Public License\r
18 along with GtkRadiant; if not, write to the Free Software\r
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\r
20 */\r
21 \r
22 #ifndef _CAMWINDOW_H_\r
23 #define _CAMWINDOW_H_\r
24 \r
25 class XYWnd;\r
26 \r
27 #include "glwindow.h"\r
28 \r
29 class rectangle_t\r
30 {\r
31 public:\r
32   rectangle_t()\r
33     : x(0), y(0), w(0), h(0)\r
34   {}\r
35   rectangle_t(float _x, float _y, float _w, float _h)\r
36     : x(_x), y(_y), w(_w), h(_h)\r
37   {}\r
38   float x;\r
39   float y;\r
40   float w;\r
41   float h;\r
42 };\r
43 \r
44 class XORRectangle\r
45 {\r
46 public:\r
47   XORRectangle(GtkWidget* widget)\r
48     : m_widget(widget), m_gc(NULL)\r
49   {}\r
50   ~XORRectangle()\r
51   {\r
52     if(initialised())\r
53       gdk_gc_unref(m_gc);\r
54   }\r
55   void set(rectangle_t rectangle)\r
56   {\r
57     lazy_init();\r
58     draw();\r
59     m_rectangle = rectangle;\r
60     draw();\r
61   }\r
62 private:\r
63   bool initialised() const\r
64   {\r
65     return m_gc != NULL;\r
66   }\r
67   void lazy_init()\r
68   {\r
69     if(!initialised())\r
70     {\r
71       m_gc = gdk_gc_new(m_widget->window);\r
72 \r
73       GdkColor color = { 0, 0xffff, 0xffff, 0xffff, };\r
74       GdkColormap* colormap = gdk_window_get_colormap(m_widget->window);\r
75       gdk_colormap_alloc_color (colormap, &color, FALSE, TRUE);\r
76       gdk_gc_copy(m_gc, m_widget->style->white_gc);\r
77       gdk_gc_set_foreground(m_gc, &color);\r
78       gdk_gc_set_background(m_gc, &color);\r
79 \r
80       gdk_gc_set_function(m_gc, GDK_XOR);\r
81     }\r
82   }\r
83   void draw() const\r
84   {\r
85     const int x = (int)m_rectangle.x;\r
86     const int y = (int)m_rectangle.y;\r
87     const int w = (int)m_rectangle.w;\r
88     const int h = (int)m_rectangle.h;\r
89     gdk_draw_rectangle(m_widget->window, m_gc, TRUE, x, -(h) - (y - m_widget->allocation.height), w, h);\r
90   }\r
91 \r
92   rectangle_t m_rectangle;\r
93 \r
94   GdkGC* m_gc;\r
95   GtkWidget* m_widget;\r
96 };\r
97 \r
98 class CamWnd : public GLWindow\r
99 {\r
100 public:\r
101   void MatchViewAxes(const vec3_t P, const vec3_t vec, int &axis, float &sgn);\r
102   void ReInitGL();\r
103   void BenchMark();\r
104   CamWnd();\r
105   virtual ~CamWnd();\r
106   camera_t *Camera(){return &m_Camera;};\r
107   void Cam_MouseControl(float dtime);\r
108   void Cam_ChangeFloor(qboolean up);\r
109   void ToggleFreeMove();\r
110   bool m_bFreeMove;\r
111 \r
112 protected:\r
113   void Cam_Init();\r
114   void Cam_BuildMatrix();\r
115   void Cam_PositionDrag();\r
116   void Cam_KeyControl(float dtime);\r
117   void Cam_MouseDown(int x, int y, int buttons);\r
118   void Cam_MouseUp (int x, int y, int buttons);\r
119   void Cam_MouseMoved (int x, int y, int buttons);\r
120   void InitCull();\r
121   qboolean CullBrush (brush_t *b);\r
122   void Cam_Draw();\r
123   void Cam_DrawStuff();\r
124   void Cam_DrawBrushes(int mode);\r
125   void Cam_DrawBrush(brush_t *b, int mode);\r
126 \r
127   brush_t* m_TransBrushes[MAX_MAP_BRUSHES];\r
128   int m_nNumTransBrushes;\r
129   camera_t m_Camera;\r
130   int   m_nCambuttonstate;\r
131   int m_ptButtonX;\r
132   int m_ptCursorX;\r
133   int m_ptLastCursorX;\r
134   int m_ptLastCamCursorX;\r
135   int m_ptButtonY;\r
136   int m_ptCursorY;\r
137   int m_ptLastCursorY;\r
138   int m_ptLastCamCursorY;\r
139   face_t* m_pSide_select;\r
140   vec3_t m_vCull1;\r
141   vec3_t m_vCull2;\r
142   int m_nCullv1[3];\r
143   int m_nCullv2[3];\r
144   bool m_bClipMode;\r
145   guint m_FocusOutHandler_id;\r
146 \r
147   void OnCreate ();\r
148   void OnExpose ();\r
149   void OnLButtonDown (guint32 flags, int x, int y);\r
150   void OnRButtonDown (guint32 flags, int x, int y);\r
151   void OnMButtonDown (guint32 flags, int x, int y);\r
152   void OnLButtonUp (guint32 flags, int pointx, int pointy);\r
153   void OnRButtonUp (guint32 flags, int pointx, int pointy);\r
154   void OnMButtonUp (guint32 flags, int pointx, int pointy);\r
155   void OnMouseMove (guint32 flags, int pointx, int pointy);\r
156   void OnMouseWheel(bool bUp);\r
157   void OnSize(int cx, int cy);\r
158 \r
159 protected:\r
160   void OriginalMouseDown (guint32 nFlags, int pointX, int pointY);\r
161   void OriginalMouseUp (guint32 nFlags, int pointX, int pointY);\r
162 \r
163 private:\r
164   XORRectangle m_XORRectangle;\r
165 \r
166   // project a point in geometric space into camera space\r
167   void ProjectCamera(const vec3_t A, vec_t B[2]);\r
168 };\r
169 \r
170 \r
171 #endif // _CAMWINDOW_H_\r