]> git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/feedback.h
Inject OpenGLBinding instead of using GlobalOpenGL() everywhere
[xonotic/netradiant.git] / radiant / feedback.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 //-----------------------------------------------------------------------------
23 //
24 // DESCRIPTION:
25 // classes used for describing geometry information from q3map feedback
26 //
27
28 #ifndef __Q3MAP_FEEDBACK__
29 #define __Q3MAP_FEEDBACK__
30
31 #include "math/vector.h"
32 #include "stream/stringstream.h"
33 #include "xmlstuff.h"
34 #include "dialog.h"
35 #include "xywindow.h"
36
37 struct OpenGLBinding;
38
39 // we use these classes to let plugins draw inside the Radiant windows
40 // 2D window like YZ XZ XY
41 class IGL2DWindow {
42 public:
43     virtual ~IGL2DWindow() = default;
44
45 // Increment the number of references to this object
46     virtual void IncRef() = 0;
47
48 // Decrement the reference count
49     virtual void DecRef() = 0;
50
51     virtual void Draw2D(OpenGLBinding &GL, VIEWTYPE vt) = 0;
52 };
53
54 // 3D window
55 class IGL3DWindow {
56 public:
57 // Increment the number of references to this object
58     virtual void IncRef() = 0;
59
60 // Decrement the reference count
61     virtual void DecRef() = 0;
62
63     virtual void Draw3D() = 0;
64 };
65
66 // a select message with a brush/entity select information
67 class CSelectMsg : public ISAXHandler {
68     enum { SELECT_MESSAGE, SELECT_BRUSH } ESelectState;
69     StringOutputStream message;
70     StringOutputStream brush;
71 public:
72     CSelectMsg()
73     { ESelectState = SELECT_MESSAGE; }
74
75 // SAX interface
76     void saxStartElement(message_info_t *ctx, const xmlChar *name, const xmlChar **attrs);
77
78     void saxEndElement(message_info_t *ctx, const xmlChar *name);
79
80     void saxCharacters(message_info_t *ctx, const xmlChar *ch, int len);
81
82 // for use in the dialog window
83     const char *getName()
84     { return message.c_str(); }
85
86     IGL2DWindow *Highlight();
87
88     void DropHighlight()
89     {}
90 };
91
92 class CPointMsg : public ISAXHandler, public IGL2DWindow {
93     enum { POINT_MESSAGE, POINT_POINT } EPointState;
94     StringOutputStream message;
95     StringOutputStream point;
96     Vector3 pt;
97     int refCount;
98 public:
99     CPointMsg()
100     {
101         EPointState = POINT_MESSAGE;
102         refCount = 0;
103     }
104
105 // SAX interface
106     void Release()
107     {
108         delete this;
109     }
110
111     void saxStartElement(message_info_t *ctx, const xmlChar *name, const xmlChar **attrs);
112
113     void saxEndElement(message_info_t *ctx, const xmlChar *name);
114
115     void saxCharacters(message_info_t *ctx, const xmlChar *ch, int len);
116
117 // for use in the dialog window
118     const char *getName()
119     { return message.c_str(); }
120
121     IGL2DWindow *Highlight();
122
123     void DropHighlight();
124
125 // IGL2DWindow interface --------------------------------
126 // Increment the number of references to this object
127     void IncRef()
128     { refCount++; }
129
130 // Decrement the reference count
131     void DecRef()
132     {
133         refCount--;
134         if (refCount <= 0) {
135             delete this;
136         }
137     }
138
139     void Draw2D(OpenGLBinding &GL, VIEWTYPE vt);
140 };
141
142 class CWindingMsg : public ISAXHandler, public IGL2DWindow {
143     enum { WINDING_MESSAGE, WINDING_WINDING } EPointState;
144     StringOutputStream message;
145     StringOutputStream winding;
146     Vector3 wt[256];
147     int numpoints;
148     int refCount;
149 public:
150     CWindingMsg()
151     {
152         EPointState = WINDING_MESSAGE;
153         refCount = 0;
154         numpoints = 0;
155     }
156
157 // SAX interface
158     void Release()
159     {
160         delete this;
161     }
162
163     void saxStartElement(message_info_t *ctx, const xmlChar *name, const xmlChar **attrs);
164
165     void saxEndElement(message_info_t *ctx, const xmlChar *name);
166
167     void saxCharacters(message_info_t *ctx, const xmlChar *ch, int len);
168
169 // for use in the dialog window
170     const char *getName()
171     { return message.c_str(); }
172
173     IGL2DWindow *Highlight();
174
175     void DropHighlight();
176
177 // IGL2DWindow interface --------------------------------
178 // Increment the number of references to this object
179     void IncRef()
180     { refCount++; }
181
182 // Decrement the reference count
183     void DecRef()
184     {
185         refCount--;
186         if (refCount <= 0) {
187             delete this;
188         }
189     }
190
191     void Draw2D(OpenGLBinding &GL, VIEWTYPE vt);
192 };
193
194
195 class CDbgDlg : public Dialog {
196     GPtrArray *m_pFeedbackElements;
197 // the list widget we use in the dialog
198     ui::ListStore m_clist{ui::null};
199     ISAXHandler *m_pHighlight;
200     IGL2DWindow *m_pDraw2D;
201 public:
202     CDbgDlg()
203     {
204         m_pFeedbackElements = g_ptr_array_new();
205         m_pHighlight = NULL;
206         m_pDraw2D = NULL;
207     }
208
209 // refresh items
210     void Push(ISAXHandler *);
211
212 // clean the debug window, release all ISAXHanlders we have
213     void Init();
214
215     ISAXHandler *GetElement(std::size_t row);
216
217     void SetHighlight(gint row);
218
219     void DropHighlight();
220
221     void draw2D(OpenGLBinding &GL, VIEWTYPE viewType)
222     {
223         if (m_pDraw2D != 0) {
224             m_pDraw2D->Draw2D(GL, viewType);
225         }
226     }
227
228     void destroyWindow()
229     {
230         if (GetWidget()) {
231             Destroy();
232         }
233     }
234 //  void HideDlg();
235 protected:
236     ui::Window BuildDialog();
237 };
238
239 extern CDbgDlg g_DbgDlg;
240
241 void Feedback_draw2D(OpenGLBinding &GL, VIEWTYPE viewType);
242
243 #endif