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