]> icculus.org git repositories - divverent/netradiant.git/blob - contrib/bobtoolz/bobToolz-GTK.cpp
NOW I do it right: #woxblox#
[divverent/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, "stair builder...") ) {
122                 DoBuildStairs();
123         } else if( string_equal_nocase(p, "door builder...") ) {
124                 DoBuildDoors();
125         } else if( string_equal_nocase(p, "intersect...") ) {
126                 DoIntersect();
127         } else if( string_equal_nocase(p, "make chain...") ) {
128                 DoMakeChain();
129         } else if( string_equal_nocase(p, "path plotter...") ) {
130                 DoPathPlotter();
131         } else if( string_equal_nocase(p, "about...") ) {
132                 DoMessageBox(PLUGIN_ABOUT, "About", eMB_OK);
133         }
134 }
135
136 const char* QERPlug_GetCommandTitleList()
137 {
138   return "";
139 }
140
141
142 #define NUM_TOOLBARBUTTONS 14
143
144 std::size_t ToolbarButtonCount( void ) {
145         return NUM_TOOLBARBUTTONS;
146 }
147
148 class CBobtoolzToolbarButton : public IToolbarButton
149 {
150 public:
151   virtual const char* getImage() const
152   {
153     switch( mIndex ) {
154                 case 0: return "bobtoolz_cleanup.bmp";
155                 case 1: return "bobtoolz_poly.bmp";
156                 case 2: return "bobtoolz_caulk.bmp";
157                 case 3: return "";
158                 case 4: return "bobtoolz_treeplanter.bmp";
159                 case 5: return "bobtoolz_trainpathplot.bmp";
160                 case 6: return "bobtoolz_dropent.bmp";
161                 case 7: return "";
162                 case 8: return "bobtoolz_merge.bmp";
163                 case 9: return "bobtoolz_split.bmp";
164                 case 10: return "bobtoolz_splitrow.bmp";
165                 case 11: return "bobtoolz_splitcol.bmp";
166         case 12: return "";
167                 case 13: return "bobtoolz_turnedge.bmp";
168     }
169     return NULL;
170   }
171   virtual EType getType() const
172   {
173     switch( mIndex ) {
174                 case 3: return eSpace;
175       case 4: return eToggleButton;
176                 case 7: return eSpace;
177                 case 12: return eSpace;
178       default: return eButton;
179     }    
180   }
181   virtual const char* getText() const
182   {
183     switch( mIndex ) {
184       case 0: return "Cleanup";
185       case 1: return "Polygons";
186       case 2: return "Caulk";
187       case 4: return "Tree Planter";
188       case 5: return "Plot Splines";
189       case 6: return "Drop Entity";
190       case 8: return "Merge 2 Patches";
191       case 9: return "Split Patch";
192       case 10: return "Split Patch Rows";
193       case 11: return "Split Patch Columns";
194       case 13: return "Flip Terrain";
195     }
196     return NULL;
197   }
198   virtual const char* getTooltip() const
199   {
200     switch( mIndex ) {
201       case 0: return "Brush Cleanup";
202       case 1: return "Polygons";
203       case 2: return "Caulk selection";
204       case 4: return "Tree Planter";
205       case 5: return "Plot Splines";
206       case 6: return "Drop Entity";
207       case 8: return "Merge 2 Patches";
208       case 9: return "Split Patch";
209           case 10: return "Split Patch Rows";
210           case 11: return "Split Patch Columns";
211       case 13: return "Flip Terrain (Turn Edge)";
212     }
213     return NULL;
214   }
215
216   virtual void activate() const
217   {
218         LoadLists();
219
220     switch( mIndex ) {
221       case 0: DoFixBrushes(); break;
222       case 1: DoPolygonsTB(); break;
223       case 2: DoCaulkSelection(); break;
224       case 4: DoTreePlanter(); break;
225       case 5: DoTrainPathPlot(); break;
226       case 6: DoDropEnts(); break;
227       case 8: DoMergePatches(); break;
228       case 9: DoSplitPatch(); break;
229           case 10: DoSplitPatchRows(); break;
230           case 11: DoSplitPatchCols(); break;
231       case 13: DoFlipTerrain(); break;
232     }
233   }
234
235   std::size_t mIndex;
236 };
237
238 CBobtoolzToolbarButton g_bobtoolzToolbarButtons[NUM_TOOLBARBUTTONS];
239
240 const IToolbarButton* GetToolbarButton(std::size_t index)
241 {
242   g_bobtoolzToolbarButtons[index].mIndex = index;
243   return &g_bobtoolzToolbarButtons[index];
244 }
245
246
247 #include "modulesystem/singletonmodule.h"
248
249 #include "iscenegraph.h"
250 #include "irender.h"
251 #include "iundo.h"
252 #include "ishaders.h"
253 #include "ipatch.h"
254 #include "ibrush.h"
255 #include "ientity.h"
256 #include "ieclass.h"
257 #include "iglrender.h"
258 #include "iplugin.h"
259
260 class BobToolzPluginDependencies :
261   public GlobalRadiantModuleRef,
262   public GlobalUndoModuleRef,
263   public GlobalSceneGraphModuleRef,
264   public GlobalSelectionModuleRef,
265   public GlobalEntityModuleRef,
266   public GlobalEntityClassManagerModuleRef,
267   public GlobalShadersModuleRef,
268   public GlobalShaderCacheModuleRef,
269   public GlobalBrushModuleRef,
270   public GlobalPatchModuleRef,
271   public GlobalOpenGLModuleRef, 
272   public GlobalOpenGLStateLibraryModuleRef
273 {
274 public:
275   BobToolzPluginDependencies() :
276     GlobalEntityModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("entities")),
277     GlobalShadersModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("shaders")),
278     GlobalBrushModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("brushtypes")),
279     GlobalPatchModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("patchtypes")),
280     GlobalEntityClassManagerModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("entityclass"))
281   {
282   }
283 };
284
285 class BobToolzPluginModule : public TypeSystemRef
286 {
287   _QERPluginTable m_plugin;
288 public:
289   typedef _QERPluginTable Type;
290   STRING_CONSTANT(Name, "bobToolz");
291
292   BobToolzPluginModule()
293   {
294     m_plugin.m_pfnQERPlug_Init = QERPlug_Init;
295     m_plugin.m_pfnQERPlug_GetName = QERPlug_GetName;
296     m_plugin.m_pfnQERPlug_GetCommandList = QERPlug_GetCommandList;
297     m_plugin.m_pfnQERPlug_GetCommandTitleList = QERPlug_GetCommandTitleList;
298     m_plugin.m_pfnQERPlug_Dispatch = QERPlug_Dispatch;
299
300     BobToolz_construct();
301   }
302   ~BobToolzPluginModule()
303   {
304     BobToolz_destroy();
305   }
306   _QERPluginTable* getTable()
307   {
308     return &m_plugin;
309   }
310 };
311
312 typedef SingletonModule<BobToolzPluginModule, BobToolzPluginDependencies> SingletonBobToolzPluginModule;
313
314 SingletonBobToolzPluginModule g_BobToolzPluginModule;
315
316
317 class BobToolzToolbarDependencies :
318   public ModuleRef<_QERPluginTable>
319 {
320 public:
321   BobToolzToolbarDependencies() :
322     ModuleRef<_QERPluginTable>("bobToolz")
323   {
324   }
325 };
326
327 class BobToolzToolbarModule : public TypeSystemRef
328 {
329   _QERPlugToolbarTable m_table;
330 public:
331   typedef _QERPlugToolbarTable Type;
332   STRING_CONSTANT(Name, "bobToolz");
333
334   BobToolzToolbarModule()
335   {
336     m_table.m_pfnToolbarButtonCount = ToolbarButtonCount;
337     m_table.m_pfnGetToolbarButton = GetToolbarButton;
338   }
339   _QERPlugToolbarTable* getTable()
340   {
341     return &m_table;
342   }
343 };
344
345 typedef SingletonModule<BobToolzToolbarModule, BobToolzToolbarDependencies> SingletonBobToolzToolbarModule;
346
347 SingletonBobToolzToolbarModule g_BobToolzToolbarModule;
348
349
350 extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules(ModuleServer& server)
351 {
352   initialiseModule(server);
353
354   g_BobToolzPluginModule.selfRegister();
355   g_BobToolzToolbarModule.selfRegister();
356 }