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