2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
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.
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.
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
22 //-----------------------------------------------------------------------------
25 // classes used for describing geometry information from q3map feedback
32 #include "debugging/debugging.h"
35 #include "iselection.h"
39 #include "mainframe.h"
44 void Feedback_draw2D(VIEWTYPE viewType)
46 g_DbgDlg.draw2D(viewType);
49 void CSelectMsg::saxStartElement(message_info_t *ctx, const xmlChar *name, const xmlChar **attrs)
51 if (string_equal(reinterpret_cast<const char *>( name ), "select")) {
53 ESelectState = SELECT_MESSAGE;
56 ASSERT_MESSAGE(string_equal(reinterpret_cast<const char *>( name ), "brush"), "FEEDBACK PARSE ERROR");
57 ASSERT_MESSAGE(ESelectState == SELECT_MESSAGE, "FEEDBACK PARSE ERROR");
58 ESelectState = SELECT_BRUSH;
59 globalOutputStream() << message.c_str() << '\n';
63 void CSelectMsg::saxEndElement(message_info_t *ctx, const xmlChar *name)
65 if (string_equal(reinterpret_cast<const char *>( name ), "select")) {
69 void CSelectMsg::saxCharacters(message_info_t *ctx, const xmlChar *ch, int len)
71 if (ESelectState == SELECT_MESSAGE) {
72 message.write(reinterpret_cast<const char *>( ch ), len);
74 brush.write(reinterpret_cast<const char *>( ch ), len);
78 IGL2DWindow *CSelectMsg::Highlight()
80 GlobalSelectionSystem().setSelectedAll(false);
81 int entitynum, brushnum;
82 if (sscanf(reinterpret_cast<const char *>( brush.c_str()), "%i %i", &entitynum, &brushnum) == 2) {
83 SelectBrush(entitynum, brushnum);
88 void CPointMsg::saxStartElement(message_info_t *ctx, const xmlChar *name, const xmlChar **attrs)
90 if (string_equal(reinterpret_cast<const char *>( name ), "pointmsg")) {
92 EPointState = POINT_MESSAGE;
95 ASSERT_MESSAGE(string_equal(reinterpret_cast<const char *>( name ), "point"), "FEEDBACK PARSE ERROR");
96 ASSERT_MESSAGE(EPointState == POINT_MESSAGE, "FEEDBACK PARSE ERROR");
97 EPointState = POINT_POINT;
98 globalOutputStream() << message.c_str() << '\n';
102 void CPointMsg::saxEndElement(message_info_t *ctx, const xmlChar *name)
104 if (string_equal(reinterpret_cast<const char *>( name ), "pointmsg")) {
105 } else if (string_equal(reinterpret_cast<const char *>( name ), "point")) {
106 sscanf(point.c_str(), "%g %g %g", &(pt[0]), &(pt[1]), &(pt[2]));
111 void CPointMsg::saxCharacters(message_info_t *ctx, const xmlChar *ch, int len)
113 if (EPointState == POINT_MESSAGE) {
114 message.write(reinterpret_cast<const char *>( ch ), len);
116 ASSERT_MESSAGE(EPointState == POINT_POINT, "FEEDBACK PARSE ERROR");
117 point.write(reinterpret_cast<const char *>( ch ), len);
121 IGL2DWindow *CPointMsg::Highlight()
126 void CPointMsg::DropHighlight()
130 void CPointMsg::Draw2D(VIEWTYPE vt)
132 int nDim1 = (vt == YZ) ? 1 : 0;
133 int nDim2 = (vt == XY) ? 1 : 2;
135 glColor3f(1.0f, 0.0f, 0.0f);
137 glVertex2f(pt[nDim1], pt[nDim2]);
139 glBegin(GL_LINE_LOOP);
140 glVertex2f(pt[nDim1] - 8, pt[nDim2] - 8);
141 glVertex2f(pt[nDim1] + 8, pt[nDim2] - 8);
142 glVertex2f(pt[nDim1] + 8, pt[nDim2] + 8);
143 glVertex2f(pt[nDim1] - 8, pt[nDim2] + 8);
147 void CWindingMsg::saxStartElement(message_info_t *ctx, const xmlChar *name, const xmlChar **attrs)
149 if (string_equal(reinterpret_cast<const char *>( name ), "windingmsg")) {
151 EPointState = WINDING_MESSAGE;
154 ASSERT_MESSAGE(string_equal(reinterpret_cast<const char *>( name ), "winding"), "FEEDBACK PARSE ERROR");
155 ASSERT_MESSAGE(EPointState == WINDING_MESSAGE, "FEEDBACK PARSE ERROR");
156 EPointState = WINDING_WINDING;
157 globalOutputStream() << message.c_str() << '\n';
161 void CWindingMsg::saxEndElement(message_info_t *ctx, const xmlChar *name)
163 if (string_equal(reinterpret_cast<const char *>( name ), "windingmsg")) {
164 } else if (string_equal(reinterpret_cast<const char *>( name ), "winding")) {
165 const char *c = winding.c_str();
166 sscanf(c, "%i ", &numpoints);
169 for (; i < numpoints; i++) {
170 c = strchr(c + 1, '(');
171 if (c) { // even if we are given the number of points when the cycle begins .. don't trust it too much
172 sscanf(c, "(%g %g %g)", &wt[i][0], &wt[i][1], &wt[i][2]);
181 void CWindingMsg::saxCharacters(message_info_t *ctx, const xmlChar *ch, int len)
183 if (EPointState == WINDING_MESSAGE) {
184 message.write(reinterpret_cast<const char *>( ch ), len);
186 ASSERT_MESSAGE(EPointState == WINDING_WINDING, "FEEDBACK PARSE ERROR");
187 winding.write(reinterpret_cast<const char *>( ch ), len);
191 IGL2DWindow *CWindingMsg::Highlight()
196 void CWindingMsg::DropHighlight()
200 void CWindingMsg::Draw2D(VIEWTYPE vt)
204 int nDim1 = (vt == YZ) ? 1 : 0;
205 int nDim2 = (vt == XY) ? 1 : 2;
206 glColor3f(1.0f, 0.f, 0.0f);
210 for (i = 0; i < numpoints; i++)
211 glVertex2f(wt[i][nDim1], wt[i][nDim2]);
216 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
217 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
218 glColor4f(0.133f, 0.4f, 1.0f, 0.5f);
220 for (i = 0; i < numpoints; i++)
221 glVertex2f(wt[i][nDim1], wt[i][nDim2]);
226 // triggered when the user selects an entry in the feedback box
227 static void feedback_selection_changed(ui::TreeSelection selection, gpointer data)
229 g_DbgDlg.DropHighlight();
232 GtkTreeIter selected;
233 if (gtk_tree_selection_get_selected(selection, &model, &selected)) {
234 auto path = gtk_tree_model_get_path(model, &selected);
235 g_DbgDlg.SetHighlight(gtk_tree_path_get_indices(path)[0]);
236 gtk_tree_path_free(path);
240 void CDbgDlg::DropHighlight()
242 if (m_pHighlight != 0) {
243 m_pHighlight->DropHighlight();
249 void CDbgDlg::SetHighlight(gint row)
251 ISAXHandler *h = GetElement(row);
253 m_pDraw2D = h->Highlight();
258 ISAXHandler *CDbgDlg::GetElement(std::size_t row)
260 return static_cast<ISAXHandler *>(g_ptr_array_index(m_pFeedbackElements, gint( row )) );
267 // free all the ISAXHandler*, clean it
268 while (m_pFeedbackElements->len) {
269 static_cast<ISAXHandler *>(g_ptr_array_index(m_pFeedbackElements, 0) )->Release();
270 g_ptr_array_remove_index(m_pFeedbackElements, 0);
278 void CDbgDlg::Push(ISAXHandler *pHandler)
281 g_ptr_array_add(m_pFeedbackElements, (void *) pHandler);
287 // put stuff in the list
289 for (std::size_t i = 0; i < static_cast<std::size_t>( m_pFeedbackElements->len ); ++i) {
290 m_clist.append(0, GetElement(i)->getName());
296 ui::Window CDbgDlg::BuildDialog()
298 auto window = MainFrame_getWindow().create_floating_window("Q3Map debug window");
300 auto scr = ui::ScrolledWindow(ui::New);
303 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scr), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
304 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scr), GTK_SHADOW_IN);
307 ui::ListStore store = ui::ListStore::from(gtk_list_store_new(1, G_TYPE_STRING));
309 auto view = ui::TreeView(ui::TreeModel::from(store._handle));
310 gtk_tree_view_set_headers_visible(view, FALSE);
313 auto renderer = ui::CellRendererText(ui::New);
314 auto column = ui::TreeViewColumn("", renderer, {{"text", 0}});
315 gtk_tree_view_append_column(view, column);
319 auto selection = ui::TreeSelection::from(gtk_tree_view_get_selection(view));
320 gtk_tree_selection_set_mode(selection, GTK_SELECTION_BROWSE);
321 selection.connect("changed", G_CALLBACK(feedback_selection_changed), NULL);