]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - contrib/bobtoolz/bobToolz-GTK.cpp
some fixes, and patch bobtoolz improvements, from osxnetradiant
[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
21
22 #include "str.h"
23 #include "qerplugin.h"
24 #include "mathlib.h"
25 #include "string/string.h"
26 #include "itoolbar.h"
27
28 #include "funchandlers.h"
29 #include "DBobView.h"
30 #include "DVisDrawer.h"
31 #include "DTrainDrawer.h"
32 #include "DTreePlanter.h"
33
34 #include "dialogs/dialogs-gtk.h"
35 #include "../../libs/cmdlib.h"
36
37 void BobToolz_construct()
38 {
39 }
40
41 void BobToolz_destroy()
42 {
43         if(g_PathView) {
44                 delete g_PathView;
45                 g_PathView = NULL;
46         }
47         if(g_VisView) {
48                 delete g_VisView;
49                 g_VisView = NULL;
50         }
51         if(g_TrainView) {
52                 delete g_TrainView;
53                 g_TrainView = NULL;
54         }
55         if(g_TreePlanter) {
56                 delete g_TreePlanter;
57                 g_TreePlanter = NULL;
58         }
59 }
60
61 // plugin name
62 char* PLUGIN_NAME = "bobToolz";
63
64 // commands in the menu
65 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,Split patches cols,Split patches rows,Turn edge";
66
67 // globals
68 GtkWidget *g_pRadiantWnd = NULL;
69
70 static const char *PLUGIN_ABOUT =       "bobToolz for SDRadiant\n"
71                                                                         "by digibob (digibob@splashdamage.com)\n"
72                                                                         "http://www.splashdamage.com\n\n"
73                                                                         "Additional Contributors:\n"
74                                                                         "MarsMattel, RR2DO2\n";
75
76 extern "C" const char* QERPlug_Init( void* hApp, void* pMainWidget ) {
77         g_pRadiantWnd = (GtkWidget*)pMainWidget;
78
79         return "bobToolz for GTKradiant";
80 }
81
82 extern "C" const char* QERPlug_GetName() {
83         return PLUGIN_NAME;
84 }
85
86 extern "C" const char* QERPlug_GetCommandList() {
87         return PLUGIN_COMMANDS;
88 }
89
90 extern "C" void QERPlug_Dispatch (const char *p, vec3_t vMin, vec3_t vMax, bool bSingleBrush) {
91         LoadLists();
92
93         if( string_equal_nocase( p, "brush cleanup" ) ) {
94     DoFixBrushes();
95   } else if( string_equal_nocase( p, "polygon builder" ) ) {
96     DoPolygonsTB();
97   } else if( string_equal_nocase( p, "caulk selection" ) ) {
98     DoCaulkSelection();
99   } else if( string_equal_nocase( p, "tree planter" ) ) {
100     DoTreePlanter();
101   } else if( string_equal_nocase( p, "plot splines" ) ) {
102     DoTrainPathPlot();
103   } else if( string_equal_nocase( p, "drop entity" ) ) {
104     DoDropEnts();
105   } else if( string_equal_nocase( p, "merge patches" ) ) {
106     DoMergePatches();
107   } else if( string_equal_nocase( p, "split patches" ) ) {
108     DoSplitPatch();
109   } else if( string_equal_nocase( p, "split patches rows" ) ) {
110         DoSplitPatchRows();
111   } else if( string_equal_nocase( p, "split patches cols" ) ) {
112         DoSplitPatchCols();
113   } else if( string_equal_nocase( p, "turn edge" ) ) {
114     DoFlipTerrain();
115   } else if( string_equal_nocase(p, "reset textures...") ) {
116                 DoResetTextures();
117         } else if( string_equal_nocase(p, "pitomatic") ) {
118                 DoPitBuilder();
119         } else if( string_equal_nocase(p, "vis viewer") ) {
120                 DoVisAnalyse();
121         } else if( string_equal_nocase(p, "about...") ) {
122                 DoMessageBox(PLUGIN_ABOUT, "About", eMB_OK);
123         }
124 }
125
126 const char* QERPlug_GetCommandTitleList()
127 {
128   return "";
129 }
130
131
132 #define NUM_TOOLBARBUTTONS 9
133
134 std::size_t ToolbarButtonCount( void ) {
135         return NUM_TOOLBARBUTTONS;
136 }
137
138 class CBobtoolzToolbarButton : public IToolbarButton
139 {
140 public:
141   virtual const char* getImage() const
142   {
143     switch( mIndex ) {
144       case 0: return "bobtoolz_cleanup.bmp";
145       case 1: return "bobtoolz_poly.bmp";
146       case 2: return "bobtoolz_caulk.bmp";
147       case 3: return "bobtoolz_treeplanter.bmp";
148       case 4: return "bobtoolz_trainpathplot.bmp";
149       case 5: return "bobtoolz_dropent.bmp";
150       case 6: return "bobtoolz_merge.bmp";
151       case 7: return "bobtoolz_split.bmp";
152       case 8: return "bobtoolz_turnedge.bmp";
153     }
154     return NULL;
155   }
156   virtual EType getType() const
157   {
158     switch( mIndex ) {
159       case 3: return eToggleButton;
160       default: return eButton;
161     }    
162   }
163   virtual const char* getText() const
164   {
165     switch( mIndex ) {
166       case 0: return "Cleanup";
167       case 1: return "Polygons";
168       case 2: return "Caulk";
169       case 3: return "Tree Planter";
170       case 4: return "Plot Splines";
171       case 5: return "Drop Entity";
172       case 6: return "Merge Patches";
173       case 7: return "Split Patches";
174       case 8: return "Flip Terrain";
175     }
176     return NULL;
177   }
178   virtual const char* getTooltip() const
179   {
180     switch( mIndex ) {
181       case 0: return "Brush Cleanup";
182       case 1: return "Polygons";
183       case 2: return "Caulk selection";
184       case 3: return "Tree Planter";
185       case 4: return "Plot Splines";
186       case 5: return "Drop Entity";
187       case 6: return "Merge Patches";
188       case 7: return "Split Patches";
189       case 8: return "Flip Terrain";
190     }
191     return NULL;
192   }
193
194   virtual void activate() const
195   {
196         LoadLists();
197
198     switch( mIndex ) {
199       case 0: DoFixBrushes(); break;
200       case 1: DoPolygonsTB(); break;
201       case 2: DoCaulkSelection(); break;
202       case 3: DoTreePlanter(); break;
203       case 4: DoTrainPathPlot(); break;
204       case 5: DoDropEnts(); break;
205       case 6: DoMergePatches(); break;
206       case 7: DoSplitPatch(); break;
207       case 8: DoFlipTerrain(); break;
208     }
209   }
210
211   std::size_t mIndex;
212 };
213
214 CBobtoolzToolbarButton g_bobtoolzToolbarButtons[NUM_TOOLBARBUTTONS];
215
216 const IToolbarButton* GetToolbarButton(std::size_t index)
217 {
218   g_bobtoolzToolbarButtons[index].mIndex = index;
219   return &g_bobtoolzToolbarButtons[index];
220 }
221
222
223 #include "modulesystem/singletonmodule.h"
224
225 #include "iscenegraph.h"
226 #include "irender.h"
227 #include "iundo.h"
228 #include "ishaders.h"
229 #include "ipatch.h"
230 #include "ibrush.h"
231 #include "ientity.h"
232 #include "ieclass.h"
233 #include "iglrender.h"
234 #include "iplugin.h"
235
236 class BobToolzPluginDependencies :
237   public GlobalRadiantModuleRef,
238   public GlobalUndoModuleRef,
239   public GlobalSceneGraphModuleRef,
240   public GlobalSelectionModuleRef,
241   public GlobalEntityModuleRef,
242   public GlobalEntityClassManagerModuleRef,
243   public GlobalShadersModuleRef,
244   public GlobalShaderCacheModuleRef,
245   public GlobalBrushModuleRef,
246   public GlobalPatchModuleRef,
247   public GlobalOpenGLModuleRef, 
248   public GlobalOpenGLStateLibraryModuleRef
249 {
250 public:
251   BobToolzPluginDependencies() :
252     GlobalEntityModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("entities")),
253     GlobalShadersModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("shaders")),
254     GlobalBrushModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("brushtypes")),
255     GlobalPatchModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("patchtypes")),
256     GlobalEntityClassManagerModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("entityclass"))
257   {
258   }
259 };
260
261 class BobToolzPluginModule : public TypeSystemRef
262 {
263   _QERPluginTable m_plugin;
264 public:
265   typedef _QERPluginTable Type;
266   STRING_CONSTANT(Name, "bobtoolz");
267
268   BobToolzPluginModule()
269   {
270     m_plugin.m_pfnQERPlug_Init = QERPlug_Init;
271     m_plugin.m_pfnQERPlug_GetName = QERPlug_GetName;
272     m_plugin.m_pfnQERPlug_GetCommandList = QERPlug_GetCommandList;
273     m_plugin.m_pfnQERPlug_GetCommandTitleList = QERPlug_GetCommandTitleList;
274     m_plugin.m_pfnQERPlug_Dispatch = QERPlug_Dispatch;
275
276     BobToolz_construct();
277   }
278   ~BobToolzPluginModule()
279   {
280     BobToolz_destroy();
281   }
282   _QERPluginTable* getTable()
283   {
284     return &m_plugin;
285   }
286 };
287
288 typedef SingletonModule<BobToolzPluginModule, BobToolzPluginDependencies> SingletonBobToolzPluginModule;
289
290 SingletonBobToolzPluginModule g_BobToolzPluginModule;
291
292
293 class BobToolzToolbarDependencies :
294   public ModuleRef<_QERPluginTable>
295 {
296 public:
297   BobToolzToolbarDependencies() :
298     ModuleRef<_QERPluginTable>("bobtoolz")
299   {
300   }
301 };
302
303 class BobToolzToolbarModule : public TypeSystemRef
304 {
305   _QERPlugToolbarTable m_table;
306 public:
307   typedef _QERPlugToolbarTable Type;
308   STRING_CONSTANT(Name, "bobtoolz");
309
310   BobToolzToolbarModule()
311   {
312     m_table.m_pfnToolbarButtonCount = ToolbarButtonCount;
313     m_table.m_pfnGetToolbarButton = GetToolbarButton;
314   }
315   _QERPlugToolbarTable* getTable()
316   {
317     return &m_table;
318   }
319 };
320
321 typedef SingletonModule<BobToolzToolbarModule, BobToolzToolbarDependencies> SingletonBobToolzToolbarModule;
322
323 SingletonBobToolzToolbarModule g_BobToolzToolbarModule;
324
325
326 extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules(ModuleServer& server)
327 {
328   initialiseModule(server);
329
330   g_BobToolzPluginModule.selfRegister();
331   g_BobToolzToolbarModule.selfRegister();
332 }