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