]> git.xonotic.org Git - xonotic/netradiant.git/blob - contrib/bobtoolz/bobToolz-GTK.cpp
uncrustify! 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 #include "StdAfx.h"
21
22 #include "funchandlers.h"
23 #include "misc.h"
24
25 #include "dialogs/dialogs-gtk.h"
26 #include "../../libs/cmdlib.h"
27
28 // Radiant function table
29 _QERFuncTable_1 g_FuncTable;
30 _QERAppDataTable g_AppDataTable;
31 _QERBrushTable g_BrushTable;
32 _QERShadersTable g_ShadersTable;                    // vvvvvvvvvvvvvvvvvvvv
33 _QERSelectedFaceTable g_SelectedFaceTable;  // to get texture sizes
34 _QERQglTable g_QglTable;                                // for path plotting (hooking to DBobView)
35 _QERUITable g_MessageTable;                             // for path plotting (listening for update)
36 _QEREntityTable g_EntityTable;
37
38 // plugin name
39 const char* PLUGIN_NAME = "bobToolz";
40
41 // commands in the menu
42 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,Turn edge";
43
44 // globals
45 GtkWidget *g_pRadiantWnd = NULL;
46
47 static const char *PLUGIN_ABOUT =   "bobToolz for SDRadiant\n"
48                                                                         "by digibob (digibob@splashdamage.com)\n"
49                                                                         "http://www.splashdamage.com\n\n"
50                                                                         "Additional Contributors:\n"
51                                                                         "MarsMattel, RR2DO2\n";
52
53 extern "C" const char* QERPlug_Init( void* hApp, void* pMainWidget ) {
54         g_pRadiantWnd = (GtkWidget*)pMainWidget;
55
56         return "bobToolz for GTKradiant";
57 }
58
59 extern "C" const char* QERPlug_GetName() {
60         return PLUGIN_NAME;
61 }
62
63 extern "C" const char* QERPlug_GetCommandList() {
64         return PLUGIN_COMMANDS;
65 }
66
67 extern "C" void QERPlug_Dispatch( const char *p, vec3_t vMin, vec3_t vMax, bool bSingleBrush ) {
68         LoadLists();
69
70         if ( !stricmp( p, "brush cleanup" ) ) {
71                 DoFixBrushes();
72         }
73         else if ( !stricmp( p, "polygon builder" ) ) {
74                 DoPolygonsTB();
75         }
76         else if ( !stricmp( p, "caulk selection" ) ) {
77                 DoCaulkSelection();
78         }
79         else if ( !stricmp( p, "tree planter" ) ) {
80                 DoTreePlanter();
81         }
82         else if ( !stricmp( p, "plot splines" ) ) {
83                 DoTrainPathPlot();
84         }
85         else if ( !stricmp( p, "drop entity" ) ) {
86                 DoDropEnts();
87         }
88         else if ( !stricmp( p, "merge patches" ) ) {
89                 DoMergePatches();
90         }
91         else if ( !stricmp( p, "split patches" ) ) {
92                 DoSplitPatch();
93         }
94         else if ( !stricmp( p, "turn edge" ) ) {
95                 DoFlipTerrain();
96         }
97         else if ( !stricmp( p, "reset textures..." ) ) {
98                 DoResetTextures();
99         }
100         else if ( !stricmp( p, "pitomatic" ) ) {
101                 DoPitBuilder( vMin, vMax );
102         }
103         else if ( !stricmp( p, "vis viewer" ) ) {
104                 DoVisAnalyse();
105         }
106         else if ( !stricmp( p, "about..." ) ) {
107                 DoMessageBox( PLUGIN_ABOUT, "About", IDOK );
108         }
109 }
110
111 #define NUM_TOOLBARBUTTONS 9
112
113 unsigned int ToolbarButtonCount( void ) {
114         return NUM_TOOLBARBUTTONS;
115 }
116
117 // Load a xpm file and return a pixmap widget.
118 GtkWidget* new_pixmap( char* filename ) {
119         GdkPixmap *gdkpixmap;
120         GdkBitmap *mask;
121         GtkWidget *pixmap;
122
123         g_FuncTable.m_pfnLoadBitmap( filename, (void **)&gdkpixmap, (void **)&mask );
124         pixmap = gtk_pixmap_new( gdkpixmap, mask );
125
126         gdk_pixmap_unref( gdkpixmap );
127         gdk_pixmap_unref( mask );
128
129         return pixmap;
130 }
131
132 class CBobtoolzToolbarButton : public IToolbarButton
133 {
134 public:
135 virtual const char* getImage() const {
136         switch ( mIndex ) {
137         case 0: return "bobtoolz_cleanup.bmp";
138         case 1: return "bobtoolz_poly.bmp";
139         case 2: return "bobtoolz_caulk.bmp";
140         case 3: return "bobtoolz_treeplanter.bmp";
141         case 4: return "bobtoolz_trainpathplot.bmp";
142         case 5: return "bobtoolz_dropent.bmp";
143         case 6: return "bobtoolz_merge.bmp";
144         case 7: return "bobtoolz_split.bmp";
145         case 8: return "bobtoolz_turnedge.bmp";
146         }
147         return NULL;
148 }
149 virtual EType getType() const {
150         switch ( mIndex ) {
151         case 3: return eToggleButton;
152         default: return eButton;
153         }
154 }
155 virtual const char* getText() const {
156         switch ( mIndex ) {
157         case 0: return "Cleanup";
158         case 1: return "Polygons";
159         case 2: return "Caulk";
160         case 3: return "Tree Planter";
161         case 4: return "Plot Splines";
162         case 5: return "Drop Entity";
163         case 6: return "Merge Patches";
164         case 7: return "Split Patches";
165         case 8: return "Flip Terrain";
166         }
167         return NULL;
168 }
169 virtual const char* getTooltip() const {
170         switch ( mIndex ) {
171         case 0: return "Brush Cleanup";
172         case 1: return "Polygons";
173         case 2: return "Caulk selection";
174         case 3: return "Tree Planter";
175         case 4: return "Plot Splines";
176         case 5: return "Drop Entity";
177         case 6: return "Merge Patches";
178         case 7: return "Split Patches";
179         case 8: return "Flip Terrain";
180         }
181         return NULL;
182 }
183
184 virtual void activate() const {
185         LoadLists();
186
187         switch ( mIndex ) {
188         case 0: DoFixBrushes(); break;
189         case 1: DoPolygonsTB(); break;
190         case 2: DoCaulkSelection(); break;
191         case 3: DoTreePlanter(); break;
192         case 4: DoTrainPathPlot(); break;
193         case 5: DoDropEnts(); break;
194         case 6: DoMergePatches(); break;
195         case 7: DoSplitPatch(); break;
196         case 8: DoFlipTerrain(); break;
197         }
198 }
199
200 int mIndex;
201 };
202
203 CBobtoolzToolbarButton g_bobtoolzToolbarButtons[NUM_TOOLBARBUTTONS];
204
205 const IToolbarButton* GetToolbarButton( unsigned int index ){
206         g_bobtoolzToolbarButtons[index].mIndex = index;
207         return &g_bobtoolzToolbarButtons[index];
208 }
209
210 // =============================================================================
211 // SYNAPSE
212
213 class CSynapseClientBobtoolz : public CSynapseClient
214 {
215 public:
216 // CSynapseClient API
217 bool RequestAPI( APIDescriptor_t *pAPI );
218 const char* GetInfo();
219
220 CSynapseClientBobtoolz() { }
221 virtual ~CSynapseClientBobtoolz() { }
222 };
223
224
225 CSynapseServer* g_pSynapseServer = NULL;
226 CSynapseClientBobtoolz g_SynapseClient;
227
228 #if __GNUC__ >= 4
229 #pragma GCC visibility push(default)
230 #endif
231 extern "C" CSynapseClient * SYNAPSE_DLL_EXPORT Synapse_EnumerateInterfaces( const char *version, CSynapseServer *pServer ) {
232 #if __GNUC__ >= 4
233 #pragma GCC visibility pop
234 #endif
235         if ( strcmp( version, SYNAPSE_VERSION ) ) {
236                 Syn_Printf( "ERROR: synapse API version mismatch: should be '" SYNAPSE_VERSION "', got '%s'\n", version );
237                 return NULL;
238         }
239         g_pSynapseServer = pServer;
240         g_pSynapseServer->IncRef();
241         Set_Syn_Printf( g_pSynapseServer->Get_Syn_Printf() );
242
243         g_SynapseClient.AddAPI( TOOLBAR_MAJOR, BOBTOOLZ_MINOR, sizeof( _QERPlugToolbarTable ) );
244         g_SynapseClient.AddAPI( PLUGIN_MAJOR, BOBTOOLZ_MINOR, sizeof( _QERPluginTable ) );
245
246         g_SynapseClient.AddAPI( DATA_MAJOR, NULL, sizeof( g_AppDataTable ), SYN_REQUIRE, &g_AppDataTable );
247         g_SynapseClient.AddAPI( BRUSH_MAJOR, NULL, sizeof( g_BrushTable ), SYN_REQUIRE, &g_BrushTable );
248         g_SynapseClient.AddAPI( SHADERS_MAJOR, "*", sizeof( g_ShadersTable ), SYN_REQUIRE, &g_ShadersTable );
249         g_SynapseClient.AddAPI( ENTITY_MAJOR, NULL, sizeof( g_EntityTable ), SYN_REQUIRE, &g_EntityTable );
250         g_SynapseClient.AddAPI( SELECTEDFACE_MAJOR, NULL, sizeof( g_SelectedFaceTable ), SYN_REQUIRE, &g_SelectedFaceTable );
251         g_SynapseClient.AddAPI( UI_MAJOR, NULL, sizeof( g_MessageTable ), SYN_REQUIRE, &g_MessageTable );
252         g_SynapseClient.AddAPI( RADIANT_MAJOR, NULL, sizeof( g_FuncTable ), SYN_REQUIRE, &g_FuncTable );
253         g_SynapseClient.AddAPI( QGL_MAJOR, NULL, sizeof( g_QglTable ), SYN_REQUIRE, &g_QglTable );
254
255         return &g_SynapseClient;
256 }
257
258 bool CSynapseClientBobtoolz::RequestAPI( APIDescriptor_t *pAPI ){
259         if ( !strcmp( pAPI->minor_name, BOBTOOLZ_MINOR ) ) {
260                 if ( !strcmp( pAPI->major_name, PLUGIN_MAJOR ) ) {
261                         _QERPluginTable* pTable = static_cast<_QERPluginTable*>( pAPI->mpTable );
262
263                         pTable->m_pfnQERPlug_Init = QERPlug_Init;
264                         pTable->m_pfnQERPlug_GetName = QERPlug_GetName;
265                         pTable->m_pfnQERPlug_GetCommandList = QERPlug_GetCommandList;
266                         pTable->m_pfnQERPlug_Dispatch = QERPlug_Dispatch;
267
268                         return true;
269                 }
270                 else if ( !strcmp( pAPI->major_name, TOOLBAR_MAJOR ) ) {
271                         _QERPlugToolbarTable* pTable = static_cast<_QERPlugToolbarTable*>( pAPI->mpTable );
272
273                         pTable->m_pfnToolbarButtonCount = &ToolbarButtonCount;
274                         pTable->m_pfnGetToolbarButton = &GetToolbarButton;
275
276                         return true;
277                 }
278         }
279
280         Syn_Printf( "ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo() );
281         return false;
282 }
283
284 #include "version.h"
285
286 const char* CSynapseClientBobtoolz::GetInfo(){
287         return "bobToolz module built " __DATE__ " " RADIANT_VERSION;
288 }
289
290 char* GetFilename( char* buffer, const char* filename ) {
291         strcpy( buffer, g_pSynapseServer->GetModuleFilename( &g_SynapseClient ) );
292         StripFilename( buffer );
293         strcat( buffer, "/" );
294         strcat( buffer, filename );
295         buffer = UnixToDosPath( buffer );
296         return buffer;
297 }