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 <glib.h>
34 #include "xmlstuff.h"
35 #include "dialog.h"
36 #include "xywindow.h"
37 
38 // we use these classes to let plugins draw inside the Radiant windows
39 // 2D window like YZ XZ XY
40 class IGL2DWindow
41 {
42 public:
43 	// Increment the number of references to this object
44 	virtual void IncRef() = 0;
45 	// Decrement the reference count
46 	virtual void DecRef() = 0;
47 	virtual void Draw2D( VIEWTYPE vt ) = 0;
48 };
49 
50 // 3D window
51 class IGL3DWindow
52 {
53 public:
54   // Increment the number of references to this object
55   virtual void IncRef() = 0;
56   // Decrement the reference count
57   virtual void DecRef() = 0;
58   virtual void Draw3D() = 0;
59 };
60 
61 // a select message with a brush/entity select information
62 class CSelectMsg : public ISAXHandler
63 {
64   enum { SELECT_MESSAGE, SELECT_BRUSH } ESelectState;
65   StringOutputStream message;
66   StringOutputStream brush;
67 public:
CSelectMsg()68   CSelectMsg() { ESelectState = SELECT_MESSAGE; }
69   // SAX interface
70   void saxStartElement (message_info_t *ctx, const xmlChar *name, const xmlChar **attrs);
71   void saxEndElement (message_info_t *ctx, const xmlChar *name);
72   void saxCharacters (message_info_t *ctx, const xmlChar *ch, int len);
73   // for use in the dialog window
getName()74   const char* getName() { return message.c_str(); }
75   IGL2DWindow* Highlight();
DropHighlight()76   void DropHighlight() { }
77 };
78 
79 class CPointMsg : public ISAXHandler, public IGL2DWindow
80 {
81   enum { POINT_MESSAGE, POINT_POINT } EPointState;
82   StringOutputStream message;
83   StringOutputStream point;
84   Vector3 pt;
85   int refCount;
86 public:
CPointMsg()87   CPointMsg() { EPointState = POINT_MESSAGE; refCount = 0; }
88   // SAX interface
Release()89   void Release()
90   {
91     delete this;
92   }
93   void saxStartElement (message_info_t *ctx, const xmlChar *name, const xmlChar **attrs);
94   void saxEndElement (message_info_t *ctx, const xmlChar *name);
95   void saxCharacters (message_info_t *ctx, const xmlChar *ch, int len);
96   // for use in the dialog window
getName()97   const char* getName() { return message.c_str(); }
98   IGL2DWindow* Highlight();
99   void DropHighlight();
100 
101   // IGL2DWindow interface --------------------------------
102 	// Increment the number of references to this object
IncRef()103   void IncRef() { refCount++; }
104 	// Decrement the reference count
DecRef()105   void DecRef() { refCount--; if (refCount <= 0) delete this; }
106 	void Draw2D( VIEWTYPE vt );
107 };
108 
109 class CWindingMsg : public ISAXHandler, public IGL2DWindow
110 {
111   enum { WINDING_MESSAGE, WINDING_WINDING } EPointState;
112   StringOutputStream message;
113   StringOutputStream winding;
114   Vector3 wt[256];
115   int numpoints;
116   int refCount;
117 public:
CWindingMsg()118   CWindingMsg() { EPointState = WINDING_MESSAGE; refCount = 0; numpoints = 0; }
119   // SAX interface
Release()120   void Release()
121   {
122     delete this;
123   }
124   void saxStartElement (message_info_t *ctx, const xmlChar *name, const xmlChar **attrs);
125   void saxEndElement (message_info_t *ctx, const xmlChar *name);
126   void saxCharacters (message_info_t *ctx, const xmlChar *ch, int len);
127   // for use in the dialog window
getName()128   const char* getName() { return message.c_str(); }
129   IGL2DWindow* Highlight();
130   void DropHighlight();
131 
132   // IGL2DWindow interface --------------------------------
133 	// Increment the number of references to this object
IncRef()134   void IncRef() { refCount++; }
135 	// Decrement the reference count
DecRef()136   void DecRef() { refCount--; if (refCount <= 0) delete this; }
137 	void Draw2D( VIEWTYPE vt );
138 };
139 
140 typedef struct _GtkListStore GtkListStore;
141 
142 class CDbgDlg : public Dialog
143 {
144   GPtrArray *m_pFeedbackElements;
145   // the list widget we use in the dialog
146   GtkListStore* m_clist;
147   ISAXHandler *m_pHighlight;
148   IGL2DWindow* m_pDraw2D;
149 public:
CDbgDlg()150   CDbgDlg()
151   {
152     m_pFeedbackElements = g_ptr_array_new();
153     m_pHighlight = NULL;
154     m_pDraw2D = NULL;
155   }
156   // refresh items
157   void Push (ISAXHandler *);
158   // clean the debug window, release all ISAXHanlders we have
159   void Init();
160   ISAXHandler *GetElement(std::size_t row);
161   void SetHighlight(gint row);
162   void DropHighlight();
draw2D(VIEWTYPE viewType)163   void draw2D(VIEWTYPE viewType)
164   {
165     if(m_pDraw2D != 0)
166     {
167       m_pDraw2D->Draw2D(viewType);
168     }
169   }
destroyWindow()170   void destroyWindow()
171   {
172     if(GetWidget() != 0)
173     {
174       Destroy();
175     }
176   }
177 //  void HideDlg();
178 protected:
179   GtkWindow* BuildDialog();
180 };
181 
182 extern CDbgDlg g_DbgDlg;
183 
184 void Feedback_draw2D(VIEWTYPE viewType);
185 
186 #endif
187