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