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