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