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