]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - contrib/gtkgensurf/plugin.cpp
uncrustify! now the code is only ugly on the *inside*
[xonotic/netradiant.git] / contrib / gtkgensurf / plugin.cpp
1 /*
2    GenSurf plugin for GtkRadiant
3    Copyright (C) 2001 David Hyde, Loki software and qeradiant.com
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 "gensurf.h"
21
22 // Global plugin FuncTable
23 _QERFuncTable_1 g_FuncTable;
24 _QERQglTable g_GLTable;
25 _QERUIGtkTable g_UIGtkTable;
26 _QEREntityTable g_EntityTable;
27 bool SingleBrushSelected;
28 bool g_bInitDone;
29
30 #include "iplugin.h"
31
32 const char* QERPlug_Init( void* hApp, void* pMainWidget ){
33         g_pRadiantWnd = (GtkWidget*)pMainWidget;
34
35         return "GenSurf for Q3Radiant";
36 }
37
38 const char* QERPlug_GetName(){
39         return "GtkGenSurf";
40 }
41
42 const char* QERPlug_GetCommandList(){
43         return "Wall facing 270...;Wall facing 180...;Wall facing 90...;Wall facing 0...;"
44                    "Ceiling...;Ground surface...;-;About...";
45 }
46
47 // vMin/vMax provide the bounds of the selection, they are zero if there is no selection
48 // if there is a selection, bSingleBrush will be true if a single brush is selected
49 // if so, typical plugin behaviour (such as primitive creation) would use the bounds as
50 // a rule to create the primitive, then delete the selection
51 void QERPlug_Dispatch( const char *p, vec3_t vMin, vec3_t vMax, bool bSingleBrush ){
52         bool Generate = false;
53
54         if ( !g_bInitDone ) {
55                 if ( GenSurfInit() ) {
56                         g_bInitDone = true;
57                 }
58         }
59
60         if ( !strcmp( p, "Ground surface..." ) ) {
61                 SingleBrushSelected = bSingleBrush;
62                 Plane = PLANE_XY0;
63                 if ( SingleBrushSelected ) {
64                         Hll = vMin[0];
65                         Vll = vMin[1];
66                         Hur = vMax[0];
67                         Vur = vMax[1];
68                         Z00 = Z01 = Z10 = Z11 = vMax[2];
69                 }
70                 Generate = true;
71         }
72         else if ( !strcmp( p, "Ceiling..." ) ) {
73                 SingleBrushSelected = bSingleBrush;
74                 Plane = PLANE_XY1;
75                 if ( SingleBrushSelected ) {
76                         Hll = vMin[0];
77                         Vll = vMin[1];
78                         Hur = vMax[0];
79                         Vur = vMax[1];
80                         Z00 = Z01 = Z10 = Z11 = vMin[2];
81                 }
82                 Generate = true;
83         }
84         else if ( !strcmp( p, "Wall facing 0..." ) ) {
85                 SingleBrushSelected = bSingleBrush;
86                 Plane = PLANE_YZ0;
87                 if ( SingleBrushSelected ) {
88                         Hll = vMin[1];
89                         Vll = vMin[2];
90                         Hur = vMax[1];
91                         Vur = vMax[2];
92                         Z00 = Z01 = Z10 = Z11 = vMax[0];
93                 }
94                 Generate = true;
95         }
96         else if ( !strcmp( p, "Wall facing 90..." ) ) {
97                 SingleBrushSelected = bSingleBrush;
98                 Plane = PLANE_XZ0;
99                 if ( SingleBrushSelected ) {
100                         Hll = vMin[0];
101                         Vll = vMin[2];
102                         Hur = vMax[0];
103                         Vur = vMax[2];
104                         Z00 = Z01 = Z10 = Z11 = vMax[1];
105                 }
106                 Generate = true;
107         }
108         else if ( !strcmp( p, "Wall facing 180..." ) ) {
109                 SingleBrushSelected = bSingleBrush;
110                 Plane = PLANE_YZ1;
111                 if ( SingleBrushSelected ) {
112                         Hll = vMin[1];
113                         Vll = vMin[2];
114                         Hur = vMax[1];
115                         Vur = vMax[2];
116                         Z00 = Z01 = Z10 = Z11 = vMin[0];
117                 }
118                 Generate = true;
119         }
120         else if ( !strcmp( p, "Wall facing 270..." ) ) {
121                 SingleBrushSelected = bSingleBrush;
122                 Plane = PLANE_XZ1;
123                 if ( SingleBrushSelected ) {
124                         Hll = vMin[0];
125                         Vll = vMin[2];
126                         Hur = vMax[0];
127                         Vur = vMax[2];
128                         Z00 = Z01 = Z10 = Z11 = vMin[1];
129                 }
130                 Generate = true;
131         }
132         else if ( !strcmp( p,"About..." ) ) {
133                 About( g_pRadiantWnd );
134         }
135
136         if ( Generate ) {
137                 if ( SingleBrushSelected ) {
138                         UseFaceBounds();
139                 }
140
141                 gtk_widget_show( g_pWnd );
142         }
143 }
144
145 extern "C" LPVOID WINAPI QERPlug_GetFuncTable(){
146         return &g_FuncTable;
147 }
148
149 // =============================================================================
150 // SYNAPSE
151
152 #include "synapse.h"
153
154 class GenSurfSynapseClient : public CSynapseClient
155 {
156 public:
157 // CSynapseClient API
158 bool RequestAPI( APIDescriptor_t *pAPI );
159 const char* GetInfo();
160
161 GenSurfSynapseClient() { }
162 virtual ~GenSurfSynapseClient() { }
163 };
164
165 CSynapseServer* g_pSynapseServer = NULL;
166 GenSurfSynapseClient g_SynapseClient;
167
168 #if __GNUC__ >= 4
169 #pragma GCC visibility push(default)
170 #endif
171 extern "C" CSynapseClient * SYNAPSE_DLL_EXPORT Synapse_EnumerateInterfaces( const char *version, CSynapseServer *pServer ) {
172 #if __GNUC__ >= 4
173 #pragma GCC visibility pop
174 #endif
175         if ( strcmp( version, SYNAPSE_VERSION ) ) {
176                 Syn_Printf( "ERROR: synapse API version mismatch: should be '" SYNAPSE_VERSION "', got '%s'\n", version );
177                 return NULL;
178         }
179         g_pSynapseServer = pServer;
180         g_pSynapseServer->IncRef();
181         Set_Syn_Printf( g_pSynapseServer->Get_Syn_Printf() );
182
183         g_SynapseClient.AddAPI( PLUGIN_MAJOR, "gtkgensurf", sizeof( _QERPluginTable ) );
184
185         g_SynapseClient.AddAPI( RADIANT_MAJOR, NULL, sizeof( _QERFuncTable_1 ), SYN_REQUIRE, &g_FuncTable );
186         g_SynapseClient.AddAPI( UIGTK_MAJOR, NULL, sizeof( _QERUIGtkTable ), SYN_REQUIRE, &g_UIGtkTable );
187         g_SynapseClient.AddAPI( QGL_MAJOR, NULL, sizeof( _QERQglTable ), SYN_REQUIRE, &g_GLTable );
188         g_SynapseClient.AddAPI( ENTITY_MAJOR, NULL, sizeof( _QEREntityTable ), SYN_REQUIRE, &g_EntityTable );
189
190         return &g_SynapseClient;
191 }
192
193 bool GenSurfSynapseClient::RequestAPI( APIDescriptor_t *pAPI ){
194         if ( !strcmp( pAPI->major_name, PLUGIN_MAJOR ) ) {
195                 _QERPluginTable* pTable = static_cast<_QERPluginTable*>( pAPI->mpTable );
196
197                 pTable->m_pfnQERPlug_Init = QERPlug_Init;
198                 pTable->m_pfnQERPlug_GetName = QERPlug_GetName;
199                 pTable->m_pfnQERPlug_GetCommandList = QERPlug_GetCommandList;
200                 pTable->m_pfnQERPlug_Dispatch = QERPlug_Dispatch;
201                 return true;
202         }
203
204         Syn_Printf( "ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo() );
205         return false;
206 }
207
208 #include "version.h"
209
210 const char* GenSurfSynapseClient::GetInfo(){
211         return "GtkGenSurf - built " __DATE__ " " RADIANT_VERSION;
212 }