2 Copyright (C) 1999-2007 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
36 void CSelectMsg::saxStartElement (message_info_t *ctx, const xmlChar *name, const xmlChar **attrs)
38 if (strcmp ((char *)name, "select")==0)
41 ESelectState = SELECT_MESSAGE;
46 assert (strcmp ((char *)name, "brush")==0);
47 assert (ESelectState == SELECT_MESSAGE);
48 ESelectState = SELECT_BRUSH;
52 void CSelectMsg::saxEndElement (message_info_t *ctx, const xmlChar *name)
54 if (strcmp ((char *)name, "select")==0)
56 ctx->bGeometry = false;
60 void CSelectMsg::saxCharacters (message_info_t *ctx, const xmlChar *ch, int len)
62 if (ESelectState == SELECT_MESSAGE)
64 message = g_string_sized_new (len+1);
65 memcpy (message->str, ch, len);
66 message->str[len]='\0';
67 Sys_Printf ("%s\n", message->str);
71 assert (ESelectState == SELECT_BRUSH);
72 sscanf ((char *)ch, "%i %i", &entitynum, &brushnum);
76 void CSelectMsg::Highlight ()
79 SelectBrush (entitynum, brushnum);
82 void CPointMsg::saxStartElement (message_info_t *ctx, const xmlChar *name, const xmlChar **attrs)
84 if (strcmp ((char *)name, "pointmsg")==0)
87 EPointState = POINT_MESSAGE;
92 assert (strcmp ((char *)name, "point")==0);
93 assert (EPointState == POINT_MESSAGE);
94 EPointState = POINT_POINT;
98 void CPointMsg::saxEndElement (message_info_t *ctx, const xmlChar *name)
100 if (strcmp ((char *)name, "pointmsg")==0)
102 ctx->bGeometry = false;
106 void CPointMsg::saxCharacters (message_info_t *ctx, const xmlChar *ch, int len)
108 if (EPointState == POINT_MESSAGE)
110 message = g_string_sized_new (len+1);
111 memcpy (message->str, ch, len);
112 message->str[len]='\0';
113 Sys_Printf ("%s\n", message->str);
117 assert (EPointState == POINT_POINT);
118 sscanf ((char *)ch, "%g %g %g", &(pt[0]), &(pt[1]), &(pt[2]));
122 void CPointMsg::Highlight ()
124 // use the entity API to push a point
125 // the API requires a ref count, we do it manually for the current instance
129 QERApp_HookGL2DWindow (this);
133 void CPointMsg::DropHighlight ()
135 assert (refCount > 0);
136 QERApp_UnHookGL2DWindow (this);
137 // do a refCount-- locally (see Highlight)
141 void CPointMsg::Draw2D( VIEWTYPE vt )
143 int nDim1 = (vt == YZ) ? 1 : 0;
144 int nDim2 = (vt == XY) ? 1 : 2;
146 qglColor3f(1.0f,0.0f,0.0f);
147 qglBegin (GL_POINTS);
148 qglVertex2f (pt[nDim1], pt[nDim2]);
150 qglBegin (GL_LINE_LOOP);
151 qglVertex2f (pt[nDim1]-8, pt[nDim2]-8);
152 qglVertex2f (pt[nDim1]+8, pt[nDim2]-8);
153 qglVertex2f (pt[nDim1]+8, pt[nDim2]+8);
154 qglVertex2f (pt[nDim1]-8, pt[nDim2]+8);
158 void CWindingMsg::saxStartElement (message_info_t *ctx, const xmlChar *name, const xmlChar **attrs)
160 if (strcmp ((char *)name, "windingmsg")==0)
163 EPointState = WINDING_MESSAGE;
168 assert (strcmp ((char *)name, "winding")==0);
169 assert (EPointState == WINDING_MESSAGE);
170 EPointState = WINDING_WINDING;
174 void CWindingMsg::saxEndElement (message_info_t *ctx, const xmlChar *name)
176 if (strcmp ((char *)name, "windingmsg")==0)
178 ctx->bGeometry = false;
182 void CWindingMsg::saxCharacters (message_info_t *ctx, const xmlChar *ch, int len)
184 if (EPointState == WINDING_MESSAGE)
186 message = g_string_sized_new (len+1);
187 memcpy (message->str, ch, len);
188 message->str[len]='\0';
189 Sys_Printf ("%s\n", message->str);
196 assert (EPointState == WINDING_WINDING);
200 sscanf (c, "%i ", &numpoints);
202 for(i = 0; i < numpoints; i++)
204 c = strchr(++c, '(');
205 if (c) // even if we are given the number of points when the cycle begins .. don't trust it too much
206 sscanf(c, "(%g %g %g)", &wt[i][0], &wt[i][1], &wt[i][2]);
214 void CWindingMsg::Highlight ()
216 // use the entity API to push a point
217 // the API requires a ref count, we do it manually for the current instance
221 QERApp_HookGL2DWindow (this);
225 void CWindingMsg::DropHighlight ()
227 assert (refCount > 0);
228 QERApp_UnHookGL2DWindow (this);
229 // do a refCount-- locally (see Highlight)
233 void CWindingMsg::Draw2D( VIEWTYPE vt )
237 int nDim1 = (vt == YZ) ? 1 : 0;
238 int nDim2 = (vt == XY) ? 1 : 2;
239 qglColor3f(1.0f,0.f,0.0f);
242 qglBegin (GL_POINTS);
243 for(i = 0; i < numpoints; i++)
244 qglVertex2f (wt[i][nDim1], wt[i][nDim2]);
248 qglEnable (GL_BLEND);
249 qglPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
250 qglBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
251 qglColor4f(0.133f,0.4f,1.0f,0.5f);
252 qglBegin (GL_POLYGON);
253 for(i = 0; i < numpoints; i++)
254 qglVertex2f (wt[i][nDim1], wt[i][nDim2]);
256 qglDisable (GL_BLEND);
259 // triggered when the user selects an entry in the feedback box
260 static void feedback_selection_changed(GtkTreeSelection* selection, gpointer data)
262 g_DbgDlg.DropHighlight();
265 GtkTreeIter selected;
266 if(gtk_tree_selection_get_selected(selection, &model, &selected))
268 GtkTreePath* path = gtk_tree_model_get_path(model, &selected);
269 g_DbgDlg.SetHighlight(gtk_tree_path_get_indices(path)[0]);
270 gtk_tree_path_free(path);
274 void CDbgDlg::DropHighlight()
278 m_pHighlight->DropHighlight();
283 void CDbgDlg::SetHighlight(gint row)
285 ISAXHandler *h = GetElement(row);
293 ISAXHandler *CDbgDlg::GetElement( gint row ) {
294 return static_cast<ISAXHandler *>( g_ptr_array_index( m_pFeedbackElements, row ) );
297 void CDbgDlg::ClearFeedbackArray() {
298 // free all the ISAXHandler*, clean it
299 while ( m_pFeedbackElements->len ) {
300 // some ISAXHandler are static and passed around but should never be deleted
301 ISAXHandler *handler = static_cast< ISAXHandler * >( g_ptr_array_index( m_pFeedbackElements, 0 ) );
302 if ( handler->ShouldDelete() ) {
305 g_ptr_array_remove_index( m_pFeedbackElements, 0 );
309 void CDbgDlg::Init() {
312 ClearFeedbackArray();
314 if ( m_clist != NULL ) {
315 gtk_list_store_clear( m_clist );
319 void CDbgDlg::Push( ISAXHandler *pHandler ) {
321 g_ptr_array_add( m_pFeedbackElements, (void *)pHandler );
323 if ( m_pWidget == NULL ) {
326 // put stuff in the list
327 gtk_list_store_clear( m_clist );
329 for ( i = 0; i < m_pFeedbackElements->len; i++ ) {
331 gtk_list_store_append( m_clist, &iter );
332 gtk_list_store_set( m_clist, &iter, 0, GetElement(i)->getName(), -1 );
338 void CDbgDlg::BuildDialog ()
340 gtk_window_set_title (GTK_WINDOW (m_pWidget), "Q3Map debug window");
342 GtkWidget* scr = gtk_scrolled_window_new (NULL, NULL);
343 gtk_widget_show (scr);
344 gtk_container_add (GTK_CONTAINER (m_pWidget), GTK_WIDGET (scr));
345 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scr), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
346 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scr), GTK_SHADOW_IN);
349 GtkListStore* store = gtk_list_store_new(1, G_TYPE_STRING);
351 GtkWidget* view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
352 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
355 GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
356 GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes("", renderer, "text", 0, NULL);
357 gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
361 GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
362 gtk_tree_selection_set_mode(selection, GTK_SELECTION_BROWSE);
363 g_signal_connect(G_OBJECT(selection), "changed", G_CALLBACK(feedback_selection_changed), NULL);
366 gtk_widget_show(view);
368 gtk_container_add(GTK_CONTAINER (scr), view);
370 g_object_unref(G_OBJECT(store));