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