]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - contrib/bobtoolz/bobToolz-GTK.cpp
fixed memleak
[xonotic/netradiant.git] / contrib / bobtoolz / bobToolz-GTK.cpp
1 /*
2 BobToolz plugin for GtkRadiant
3 Copyright (C) 2001 Gordon Biggans
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 */
19
20 #include "libxml/parser.h"
21
22
23 #include "str.h"
24
25 #include "funchandlers.h"
26
27 #include "dialogs/dialogs-gtk.h"
28 #include "../../libs/cmdlib.h"
29
30 void BobToolz_construct()
31 {
32 }
33
34 void BobToolz_destroy()
35 {
36 }
37
38 // Radiant function table
39 _QERFuncTable_1                   __QERTABLENAME;
40 _QERShadersTable                  __SHADERSTABLENAME;                   // vvvvvvvvvvvvvvvvvvvv
41 _QERQglTable                              __QGLTABLENAME;                               // for path plotting (hooking to DBobView)
42 _QERUITable                                       g_MessageTable;                       // for path plotting (listening for update)
43 _QEREntityTable                   __ENTITYTABLENAME;
44 _QERBrushTable                    __BRUSHTABLENAME;
45 _QERPatchTable                    __PATCHTABLENAME;
46
47 // plugin name
48 char* PLUGIN_NAME = "bobToolz";
49
50 // commands in the menu
51 static char* PLUGIN_COMMANDS = "About...,-,Reset Textures...,PitOMatic,-,Vis Viewer,Brush Cleanup,Polygon Builder,Caulk Selection,-,Tree Planter,Drop Entity,Plot Splines,-,Merge Patches,Split patches,Turn edge";
52
53 // globals
54 GtkWidget *g_pRadiantWnd = NULL;
55
56 static const char *PLUGIN_ABOUT =       "bobToolz for SDRadiant\n"
57                                                                         "by digibob (digibob@splashdamage.com)\n"
58                                                                         "http://www.splashdamage.com\n\n"
59                                                                         "Additional Contributors:\n"
60                                                                         "MarsMattel, RR2DO2\n";
61
62 extern "C" const char* QERPlug_Init( void* hApp, void* pMainWidget ) {
63         g_pRadiantWnd = (GtkWidget*)pMainWidget;
64
65         return "bobToolz for GTKradiant";
66 }
67
68 extern "C" const char* QERPlug_GetName() {
69         return PLUGIN_NAME;
70 }
71
72 extern "C" const char* QERPlug_GetCommandList() {
73         return PLUGIN_COMMANDS;
74 }
75
76 extern "C" void QERPlug_Dispatch (const char *p, vec3_t vMin, vec3_t vMax, bool bSingleBrush) {
77         LoadLists();
78
79         if( string_equal_nocase( p, "brush cleanup" ) ) {
80     DoFixBrushes();
81   } else if( string_equal_nocase( p, "polygon builder" ) ) {
82     DoPolygonsTB();
83   } else if( string_equal_nocase( p, "caulk selection" ) ) {
84     DoCaulkSelection();
85   } else if( string_equal_nocase( p, "tree planter" ) ) {
86     DoTreePlanter();
87   } else if( string_equal_nocase( p, "plot splines" ) ) {
88     DoTrainPathPlot();
89   } else if( string_equal_nocase( p, "drop entity" ) ) {
90     DoDropEnts();
91   } else if( string_equal_nocase( p, "merge patches" ) ) {
92     DoMergePatches();
93   } else if( string_equal_nocase( p, "split patches" ) ) {
94     DoSplitPatch();
95   } else if( string_equal_nocase( p, "turn edge" ) ) {
96     DoFlipTerrain();
97   } else if( string_equal_nocase(p, "reset textures...") ) {
98                 DoResetTextures();
99         } else if( string_equal_nocase(p, "pitomatic") ) {
100                 DoPitBuilder();
101         } else if( string_equal_nocase(p, "vis viewer") ) {
102                 DoVisAnalyse();
103         } else if( string_equal_nocase(p, "about...") ) {
104                 DoMessageBox(PLUGIN_ABOUT, "About", eMB_OK);
105         }
106 }
107
108 #define NUM_TOOLBARBUTTONS 9
109
110 unsigned int ToolbarButtonCount( void ) {
111         return NUM_TOOLBARBUTTONS;
112 }
113
114 // Load a xpm file and return a pixmap widget.
115 GtkWidget* new_pixmap (char* filename) {
116         GdkPixmap *gdkpixmap;
117         GdkBitmap *mask;
118         GtkWidget *pixmap;
119
120         g_FuncTable.m_pfnLoadBitmap(filename, (void **)&gdkpixmap, (void **)&mask);     
121         pixmap = gtk_pixmap_new (gdkpixmap, mask);
122
123         gdk_pixmap_unref (gdkpixmap);
124         gdk_pixmap_unref (mask);
125
126         return pixmap;
127
128
129 class CBobtoolzToolbarButton : public IToolbarButton
130 {
131 public:
132   virtual const char* getImage() const
133   {
134     switch( mIndex ) {
135       case 0: return "bobtoolz_cleanup.bmp";
136       case 1: return "bobtoolz_poly.bmp";
137       case 2: return "bobtoolz_caulk.bmp";
138       case 3: return "bobtoolz_treeplanter.bmp";
139       case 4: return "bobtoolz_trainpathplot.bmp";
140       case 5: return "bobtoolz_dropent.bmp";
141       case 6: return "bobtoolz_merge.bmp";
142       case 7: return "bobtoolz_split.bmp";
143       case 8: return "bobtoolz_turnedge.bmp";
144     }
145     return NULL;
146   }
147   virtual EType getType() const
148   {
149     switch( mIndex ) {
150       case 3: return eToggleButton;
151       default: return eButton;
152     }    
153   }
154   virtual const char* getText() const
155   {
156     switch( mIndex ) {
157       case 0: return "Cleanup";
158       case 1: return "Polygons";
159       case 2: return "Caulk";
160       case 3: return "Tree Planter";
161       case 4: return "Plot Splines";
162       case 5: return "Drop Entity";
163       case 6: return "Merge Patches";
164       case 7: return "Split Patches";
165       case 8: return "Flip Terrain";
166     }
167     return NULL;
168   }
169   virtual const char* getTooltip() const
170   {
171     switch( mIndex ) {
172       case 0: return "Brush Cleanup";
173       case 1: return "Polygons";
174       case 2: return "Caulk selection";
175       case 3: return "Tree Planter";
176       case 4: return "Plot Splines";
177       case 5: return "Drop Entity";
178       case 6: return "Merge Patches";
179       case 7: return "Split Patches";
180       case 8: return "Flip Terrain";
181     }
182     return NULL;
183   }
184
185   virtual void activate() const
186   {
187         LoadLists();
188
189     switch( mIndex ) {
190       case 0: DoFixBrushes(); break;
191       case 1: DoPolygonsTB(); break;
192       case 2: DoCaulkSelection(); break;
193       case 3: DoTreePlanter(); break;
194       case 4: DoTrainPathPlot(); break;
195       case 5: DoDropEnts(); break;
196       case 6: DoMergePatches(); break;
197       case 7: DoSplitPatch(); break;
198       case 8: DoFlipTerrain(); break;
199     }
200   }
201
202   int mIndex;
203 };
204
205 CBobtoolzToolbarButton g_bobtoolzToolbarButtons[NUM_TOOLBARBUTTONS];
206
207 const IToolbarButton* GetToolbarButton(unsigned int index)
208 {
209   g_bobtoolzToolbarButtons[index].mIndex = index;
210   return &g_bobtoolzToolbarButtons[index];
211 }
212
213 // =============================================================================
214 // SYNAPSE
215
216 #include "synapse.h"
217
218 class CSynapseClientBobtoolz : public CSynapseClient
219 {
220 public:
221   // CSynapseClient API
222   bool RequestAPI(APIDescriptor_t *pAPI);
223   const char* GetInfo();
224   
225   CSynapseClientBobtoolz() { }
226   virtual ~CSynapseClientBobtoolz() { }
227 };
228
229 #define BOBTOOLZ_MINOR "bobtoolz"
230
231 CSynapseServer* g_pSynapseServer = NULL;
232 CSynapseClientBobtoolz g_SynapseClient;
233
234 extern "C" CSynapseClient* SYNAPSE_DLL_EXPORT Synapse_EnumerateInterfaces (const char *version, CSynapseServer *pServer)
235 {
236   if (strcmp(version, SYNAPSE_VERSION))
237   {
238     Syn_Printf("ERROR: synapse API version mismatch: should be '" SYNAPSE_VERSION "', got '%s'\n", version);
239     return NULL;
240   }
241   g_pSynapseServer = pServer;
242   g_pSynapseServer->IncRef();
243   Set_Syn_Printf(g_pSynapseServer->Get_Syn_Printf());
244     
245   g_SynapseClient.AddAPI(TOOLBAR_MAJOR, BOBTOOLZ_MINOR, sizeof(_QERPlugToolbarTable));
246   g_SynapseClient.AddAPI(PLUGIN_MAJOR, BOBTOOLZ_MINOR, sizeof(_QERPluginTable));
247
248   g_SynapseClient.AddAPI(BRUSH_MAJOR, NULL, sizeof(__BRUSHTABLENAME), SYN_REQUIRE, &g_BrushTable);
249   g_SynapseClient.AddAPI(PATCH_MAJOR, NULL, sizeof(__PATCHTABLENAME), SYN_REQUIRE, &g_BrushTable);
250   g_SynapseClient.AddAPI(SHADERS_MAJOR, "*", sizeof(g_ShadersTable), SYN_REQUIRE, &g_ShadersTable);
251   g_SynapseClient.AddAPI(ENTITY_MAJOR, NULL, sizeof(g_EntityTable), SYN_REQUIRE, &g_EntityTable);
252   g_SynapseClient.AddAPI(SELECTEDFACE_MAJOR, NULL, sizeof(g_SelectedFaceTable), SYN_REQUIRE, &g_SelectedFaceTable);
253   g_SynapseClient.AddAPI(UI_MAJOR, NULL, sizeof(g_MessageTable), SYN_REQUIRE, &g_MessageTable);
254   g_SynapseClient.AddAPI(RADIANT_MAJOR, NULL, sizeof(__QERTABLENAME), SYN_REQUIRE, &g_FuncTable);
255   g_SynapseClient.AddAPI(QGL_MAJOR, NULL, sizeof(g_QglTable), SYN_REQUIRE, &g_QglTable);
256
257   return &g_SynapseClient;
258 }
259
260 bool CSynapseClientBobtoolz::RequestAPI(APIDescriptor_t *pAPI)
261 {
262   if( !strcmp(pAPI->minor_name, BOBTOOLZ_MINOR) )
263   {
264     if( !strcmp(pAPI->major_name, PLUGIN_MAJOR) )
265     {
266       _QERPluginTable* pTable= static_cast<_QERPluginTable*>(pAPI->mpTable);
267
268       pTable->m_pfnQERPlug_Init = QERPlug_Init;
269       pTable->m_pfnQERPlug_GetName = QERPlug_GetName;
270       pTable->m_pfnQERPlug_GetCommandList = QERPlug_GetCommandList;
271       pTable->m_pfnQERPlug_Dispatch = QERPlug_Dispatch;
272
273       return true;
274     }
275     else if( !strcmp(pAPI->major_name, TOOLBAR_MAJOR) )
276     {
277       _QERPlugToolbarTable* pTable= static_cast<_QERPlugToolbarTable*>(pAPI->mpTable);
278
279       pTable->m_pfnToolbarButtonCount = &ToolbarButtonCount;
280       pTable->m_pfnGetToolbarButton = &GetToolbarButton;
281
282       return true;
283     }
284   }
285
286   Syn_Printf("ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo());
287   return false;
288 }
289
290 #include "version.h"
291
292 const char* CSynapseClientBobtoolz::GetInfo()
293 {
294   return "bobToolz module built " __DATE__ " " RADIANT_VERSION;
295 }
296