2 BobToolz plugin for GtkRadiant
3 Copyright (C) 2001 Gordon Biggans
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.
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.
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
20 #include "libxml/parser.h"
25 #include "funchandlers.h"
27 #include "dialogs/dialogs-gtk.h"
28 #include "../../libs/cmdlib.h"
30 void BobToolz_construct()
34 void BobToolz_destroy()
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;
48 char* PLUGIN_NAME = "bobToolz";
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";
54 GtkWidget *g_pRadiantWnd = NULL;
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";
62 extern "C" const char* QERPlug_Init( void* hApp, void* pMainWidget ) {
63 g_pRadiantWnd = (GtkWidget*)pMainWidget;
65 return "bobToolz for GTKradiant";
68 extern "C" const char* QERPlug_GetName() {
72 extern "C" const char* QERPlug_GetCommandList() {
73 return PLUGIN_COMMANDS;
76 extern "C" void QERPlug_Dispatch (const char *p, vec3_t vMin, vec3_t vMax, bool bSingleBrush) {
79 if( string_equal_nocase( p, "brush cleanup" ) ) {
81 } else if( string_equal_nocase( p, "polygon builder" ) ) {
83 } else if( string_equal_nocase( p, "caulk selection" ) ) {
85 } else if( string_equal_nocase( p, "tree planter" ) ) {
87 } else if( string_equal_nocase( p, "plot splines" ) ) {
89 } else if( string_equal_nocase( p, "drop entity" ) ) {
91 } else if( string_equal_nocase( p, "merge patches" ) ) {
93 } else if( string_equal_nocase( p, "split patches" ) ) {
95 } else if( string_equal_nocase( p, "turn edge" ) ) {
97 } else if( string_equal_nocase(p, "reset textures...") ) {
99 } else if( string_equal_nocase(p, "pitomatic") ) {
101 } else if( string_equal_nocase(p, "vis viewer") ) {
103 } else if( string_equal_nocase(p, "about...") ) {
104 DoMessageBox(PLUGIN_ABOUT, "About", eMB_OK);
108 #define NUM_TOOLBARBUTTONS 9
110 unsigned int ToolbarButtonCount( void ) {
111 return NUM_TOOLBARBUTTONS;
114 // Load a xpm file and return a pixmap widget.
115 GtkWidget* new_pixmap (char* filename) {
116 GdkPixmap *gdkpixmap;
120 g_FuncTable.m_pfnLoadBitmap(filename, (void **)&gdkpixmap, (void **)&mask);
121 pixmap = gtk_pixmap_new (gdkpixmap, mask);
123 gdk_pixmap_unref (gdkpixmap);
124 gdk_pixmap_unref (mask);
129 class CBobtoolzToolbarButton : public IToolbarButton
132 virtual const char* getImage() const
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";
147 virtual EType getType() const
150 case 3: return eToggleButton;
151 default: return eButton;
154 virtual const char* getText() const
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";
169 virtual const char* getTooltip() const
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";
185 virtual void activate() const
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;
205 CBobtoolzToolbarButton g_bobtoolzToolbarButtons[NUM_TOOLBARBUTTONS];
207 const IToolbarButton* GetToolbarButton(unsigned int index)
209 g_bobtoolzToolbarButtons[index].mIndex = index;
210 return &g_bobtoolzToolbarButtons[index];
213 // =============================================================================
218 class CSynapseClientBobtoolz : public CSynapseClient
221 // CSynapseClient API
222 bool RequestAPI(APIDescriptor_t *pAPI);
223 const char* GetInfo();
225 CSynapseClientBobtoolz() { }
226 virtual ~CSynapseClientBobtoolz() { }
229 #define BOBTOOLZ_MINOR "bobtoolz"
231 CSynapseServer* g_pSynapseServer = NULL;
232 CSynapseClientBobtoolz g_SynapseClient;
234 extern "C" CSynapseClient* SYNAPSE_DLL_EXPORT Synapse_EnumerateInterfaces (const char *version, CSynapseServer *pServer)
236 if (strcmp(version, SYNAPSE_VERSION))
238 Syn_Printf("ERROR: synapse API version mismatch: should be '" SYNAPSE_VERSION "', got '%s'\n", version);
241 g_pSynapseServer = pServer;
242 g_pSynapseServer->IncRef();
243 Set_Syn_Printf(g_pSynapseServer->Get_Syn_Printf());
245 g_SynapseClient.AddAPI(TOOLBAR_MAJOR, BOBTOOLZ_MINOR, sizeof(_QERPlugToolbarTable));
246 g_SynapseClient.AddAPI(PLUGIN_MAJOR, BOBTOOLZ_MINOR, sizeof(_QERPluginTable));
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);
257 return &g_SynapseClient;
260 bool CSynapseClientBobtoolz::RequestAPI(APIDescriptor_t *pAPI)
262 if( !strcmp(pAPI->minor_name, BOBTOOLZ_MINOR) )
264 if( !strcmp(pAPI->major_name, PLUGIN_MAJOR) )
266 _QERPluginTable* pTable= static_cast<_QERPluginTable*>(pAPI->mpTable);
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;
275 else if( !strcmp(pAPI->major_name, TOOLBAR_MAJOR) )
277 _QERPlugToolbarTable* pTable= static_cast<_QERPlugToolbarTable*>(pAPI->mpTable);
279 pTable->m_pfnToolbarButtonCount = &ToolbarButtonCount;
280 pTable->m_pfnGetToolbarButton = &GetToolbarButton;
286 Syn_Printf("ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo());
292 const char* CSynapseClientBobtoolz::GetInfo()
294 return "bobToolz module built " __DATE__ " " RADIANT_VERSION;