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