]> git.xonotic.org Git - xonotic/netradiant.git/blob - contrib/bobtoolz/bobToolz-GTK.cpp
reformat code! now the code is only ugly on the *inside*
[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 const char *PLUGIN_NAME = "bobToolz";
63
64 // commands in the menu
65 static const 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 ui::Window g_pRadiantWnd{ui::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 {
78     g_pRadiantWnd = ui::Window::from(pMainWidget);
79
80     return "bobToolz for GTKradiant";
81 }
82
83 extern "C" const char *QERPlug_GetName()
84 {
85     return PLUGIN_NAME;
86 }
87
88 extern "C" const char *QERPlug_GetCommandList()
89 {
90     return PLUGIN_COMMANDS;
91 }
92
93 extern "C" void QERPlug_Dispatch(const char *p, vec3_t vMin, vec3_t vMax, bool bSingleBrush)
94 {
95     LoadLists();
96
97     if (string_equal_nocase(p, "brush cleanup")) {
98         DoFixBrushes();
99     } else if (string_equal_nocase(p, "polygon builder")) {
100         DoPolygonsTB();
101     } else if (string_equal_nocase(p, "caulk selection")) {
102         DoCaulkSelection();
103     } else if (string_equal_nocase(p, "tree planter")) {
104         DoTreePlanter();
105     } else if (string_equal_nocase(p, "plot splines")) {
106         DoTrainPathPlot();
107     } else if (string_equal_nocase(p, "drop entity")) {
108         DoDropEnts();
109     } else if (string_equal_nocase(p, "merge patches")) {
110         DoMergePatches();
111     } else if (string_equal_nocase(p, "split patches")) {
112         DoSplitPatch();
113     } else if (string_equal_nocase(p, "split patches rows")) {
114         DoSplitPatchRows();
115     } else if (string_equal_nocase(p, "split patches cols")) {
116         DoSplitPatchCols();
117     } else if (string_equal_nocase(p, "turn edge")) {
118         DoFlipTerrain();
119     } else if (string_equal_nocase(p, "reset textures...")) {
120         DoResetTextures();
121     } else if (string_equal_nocase(p, "pitomatic")) {
122         DoPitBuilder();
123     } else if (string_equal_nocase(p, "vis viewer")) {
124         DoVisAnalyse();
125     } else if (string_equal_nocase(p, "stair builder...")) {
126         DoBuildStairs();
127     } else if (string_equal_nocase(p, "door builder...")) {
128         DoBuildDoors();
129     } else if (string_equal_nocase(p, "intersect...")) {
130         DoIntersect();
131     } else if (string_equal_nocase(p, "make chain...")) {
132         DoMakeChain();
133     } else if (string_equal_nocase(p, "path plotter...")) {
134         DoPathPlotter();
135     } else if (string_equal_nocase(p, "about...")) {
136         DoMessageBox(PLUGIN_ABOUT, "About", eMB_OK);
137     }
138 }
139
140 const char *QERPlug_GetCommandTitleList()
141 {
142     return "";
143 }
144
145
146 const int NUM_TOOLBARBUTTONS = 14;
147
148 std::size_t ToolbarButtonCount(void)
149 {
150     return NUM_TOOLBARBUTTONS;
151 }
152
153 class CBobtoolzToolbarButton : public IToolbarButton {
154 public:
155     virtual const char *getImage() const
156     {
157         switch (mIndex) {
158             case 0:
159                 return "bobtoolz_cleanup.png";
160             case 1:
161                 return "bobtoolz_poly.png";
162             case 2:
163                 return "bobtoolz_caulk.png";
164             case 3:
165                 return "";
166             case 4:
167                 return "bobtoolz_treeplanter.png";
168             case 5:
169                 return "bobtoolz_trainpathplot.png";
170             case 6:
171                 return "bobtoolz_dropent.png";
172             case 7:
173                 return "";
174             case 8:
175                 return "bobtoolz_merge.png";
176             case 9:
177                 return "bobtoolz_split.png";
178             case 10:
179                 return "bobtoolz_splitrow.png";
180             case 11:
181                 return "bobtoolz_splitcol.png";
182             case 12:
183                 return "";
184             case 13:
185                 return "bobtoolz_turnedge.png";
186         }
187         return NULL;
188     }
189
190     virtual EType getType() const
191     {
192         switch (mIndex) {
193             case 3:
194                 return eSpace;
195             case 4:
196                 return eToggleButton;
197             case 7:
198                 return eSpace;
199             case 12:
200                 return eSpace;
201             default:
202                 return eButton;
203         }
204     }
205
206     virtual const char *getText() const
207     {
208         switch (mIndex) {
209             case 0:
210                 return "Cleanup";
211             case 1:
212                 return "Polygons";
213             case 2:
214                 return "Caulk";
215             case 4:
216                 return "Tree Planter";
217             case 5:
218                 return "Plot Splines";
219             case 6:
220                 return "Drop Entity";
221             case 8:
222                 return "Merge 2 Patches";
223             case 9:
224                 return "Split Patch";
225             case 10:
226                 return "Split Patch Rows";
227             case 11:
228                 return "Split Patch Columns";
229             case 13:
230                 return "Flip Terrain";
231         }
232         return NULL;
233     }
234
235     virtual const char *getTooltip() const
236     {
237         switch (mIndex) {
238             case 0:
239                 return "Brush Cleanup";
240             case 1:
241                 return "Polygons";
242             case 2:
243                 return "Caulk selection";
244             case 4:
245                 return "Tree Planter";
246             case 5:
247                 return "Plot Splines";
248             case 6:
249                 return "Drop Entity";
250             case 8:
251                 return "Merge 2 Patches";
252             case 9:
253                 return "Split Patch";
254             case 10:
255                 return "Split Patch Rows";
256             case 11:
257                 return "Split Patch Columns";
258             case 13:
259                 return "Flip Terrain (Turn Edge)";
260         }
261         return NULL;
262     }
263
264     virtual void activate() const
265     {
266         LoadLists();
267
268         switch (mIndex) {
269             case 0:
270                 DoFixBrushes();
271                 break;
272             case 1:
273                 DoPolygonsTB();
274                 break;
275             case 2:
276                 DoCaulkSelection();
277                 break;
278             case 4:
279                 DoTreePlanter();
280                 break;
281             case 5:
282                 DoTrainPathPlot();
283                 break;
284             case 6:
285                 DoDropEnts();
286                 break;
287             case 8:
288                 DoMergePatches();
289                 break;
290             case 9:
291                 DoSplitPatch();
292                 break;
293             case 10:
294                 DoSplitPatchRows();
295                 break;
296             case 11:
297                 DoSplitPatchCols();
298                 break;
299             case 13:
300                 DoFlipTerrain();
301                 break;
302         }
303     }
304
305     std::size_t mIndex;
306 };
307
308 CBobtoolzToolbarButton g_bobtoolzToolbarButtons[NUM_TOOLBARBUTTONS];
309
310 const IToolbarButton *GetToolbarButton(std::size_t index)
311 {
312     g_bobtoolzToolbarButtons[index].mIndex = index;
313     return &g_bobtoolzToolbarButtons[index];
314 }
315
316
317 #include "modulesystem/singletonmodule.h"
318
319 #include "iscenegraph.h"
320 #include "irender.h"
321 #include "iundo.h"
322 #include "ishaders.h"
323 #include "ipatch.h"
324 #include "ibrush.h"
325 #include "ientity.h"
326 #include "ieclass.h"
327 #include "iglrender.h"
328 #include "iplugin.h"
329
330 class BobToolzPluginDependencies :
331         public GlobalRadiantModuleRef,
332         public GlobalUndoModuleRef,
333         public GlobalSceneGraphModuleRef,
334         public GlobalSelectionModuleRef,
335         public GlobalEntityModuleRef,
336         public GlobalEntityClassManagerModuleRef,
337         public GlobalShadersModuleRef,
338         public GlobalShaderCacheModuleRef,
339         public GlobalBrushModuleRef,
340         public GlobalPatchModuleRef,
341         public GlobalOpenGLModuleRef,
342         public GlobalOpenGLStateLibraryModuleRef {
343 public:
344     BobToolzPluginDependencies() :
345             GlobalEntityModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("entities")),
346             GlobalEntityClassManagerModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("entityclass")),
347             GlobalShadersModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("shaders")),
348             GlobalBrushModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("brushtypes")),
349             GlobalPatchModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("patchtypes"))
350     {
351     }
352 };
353
354 class BobToolzPluginModule : public TypeSystemRef {
355     _QERPluginTable m_plugin;
356 public:
357     typedef _QERPluginTable Type;
358
359     STRING_CONSTANT(Name, "bobToolz");
360
361     BobToolzPluginModule()
362     {
363         m_plugin.m_pfnQERPlug_Init = QERPlug_Init;
364         m_plugin.m_pfnQERPlug_GetName = QERPlug_GetName;
365         m_plugin.m_pfnQERPlug_GetCommandList = QERPlug_GetCommandList;
366         m_plugin.m_pfnQERPlug_GetCommandTitleList = QERPlug_GetCommandTitleList;
367         m_plugin.m_pfnQERPlug_Dispatch = QERPlug_Dispatch;
368
369         BobToolz_construct();
370     }
371
372     ~BobToolzPluginModule()
373     {
374         BobToolz_destroy();
375     }
376
377     _QERPluginTable *getTable()
378     {
379         return &m_plugin;
380     }
381 };
382
383 typedef SingletonModule<BobToolzPluginModule, BobToolzPluginDependencies> SingletonBobToolzPluginModule;
384
385 SingletonBobToolzPluginModule g_BobToolzPluginModule;
386
387
388 class BobToolzToolbarDependencies :
389         public ModuleRef<_QERPluginTable> {
390 public:
391     BobToolzToolbarDependencies() :
392             ModuleRef<_QERPluginTable>("bobToolz")
393     {
394     }
395 };
396
397 class BobToolzToolbarModule : public TypeSystemRef {
398     _QERPlugToolbarTable m_table;
399 public:
400     typedef _QERPlugToolbarTable Type;
401
402     STRING_CONSTANT(Name, "bobToolz");
403
404     BobToolzToolbarModule()
405     {
406         m_table.m_pfnToolbarButtonCount = ToolbarButtonCount;
407         m_table.m_pfnGetToolbarButton = GetToolbarButton;
408     }
409
410     _QERPlugToolbarTable *getTable()
411     {
412         return &m_table;
413     }
414 };
415
416 typedef SingletonModule<BobToolzToolbarModule, BobToolzToolbarDependencies> SingletonBobToolzToolbarModule;
417
418 SingletonBobToolzToolbarModule g_BobToolzToolbarModule;
419
420
421 extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules(ModuleServer &server)
422 {
423     initialiseModule(server);
424
425     g_BobToolzPluginModule.selfRegister();
426     g_BobToolzToolbarModule.selfRegister();
427 }