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