]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - contrib/gtkgensurf/plugin.cpp
d7825cc251588db5eec578fb578a634c23d41840
[xonotic/netradiant.git] / contrib / gtkgensurf / plugin.cpp
1 /*\r
2 GenSurf plugin for GtkRadiant\r
3 Copyright (C) 2001 David Hyde, Loki software and qeradiant.com\r
4 \r
5 This library is free software; you can redistribute it and/or\r
6 modify it under the terms of the GNU Lesser General Public\r
7 License as published by the Free Software Foundation; either\r
8 version 2.1 of the License, or (at your option) any later version.\r
9 \r
10 This library is distributed in the hope that it will be useful,\r
11 but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
13 Lesser General Public License for more details.\r
14 \r
15 You should have received a copy of the GNU Lesser General Public\r
16 License along with this library; if not, write to the Free Software\r
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
18 */\r
19 \r
20 #include "gensurf.h"\r
21 \r
22 // Global plugin FuncTable\r
23 _QERFuncTable_1 g_FuncTable;\r
24 _QERQglTable g_GLTable;\r
25 _QERUIGtkTable g_UIGtkTable;\r
26 _QEREntityTable g_EntityTable;\r
27 bool SingleBrushSelected;\r
28 bool g_bInitDone;\r
29 \r
30 #include "iplugin.h"\r
31 \r
32 const char* QERPlug_Init(void* hApp, void* pMainWidget)\r
33 {\r
34   g_pRadiantWnd = (GtkWidget*)pMainWidget;\r
35 \r
36   return "GenSurf for Q3Radiant";\r
37 }\r
38 \r
39 const char* QERPlug_GetName ()\r
40 {\r
41   return "GtkGenSurf";\r
42 }\r
43 \r
44 const char* QERPlug_GetCommandList ()\r
45 {\r
46   return "Wall facing 270...;Wall facing 180...;Wall facing 90...;Wall facing 0...;"\r
47          "Ceiling...;Ground surface...;-;About...";\r
48 }\r
49 \r
50 // vMin/vMax provide the bounds of the selection, they are zero if there is no selection\r
51 // if there is a selection, bSingleBrush will be true if a single brush is selected\r
52 // if so, typical plugin behaviour (such as primitive creation) would use the bounds as\r
53 // a rule to create the primitive, then delete the selection\r
54 void QERPlug_Dispatch (const char *p, vec3_t vMin, vec3_t vMax, bool bSingleBrush)\r
55 {\r
56   bool Generate = false;\r
57 \r
58   if (!g_bInitDone)\r
59   {\r
60     if (GenSurfInit ())\r
61       g_bInitDone = true;\r
62   }\r
63 \r
64   if (!strcmp (p, "Ground surface..."))\r
65   {\r
66     SingleBrushSelected = bSingleBrush;\r
67     Plane = PLANE_XY0;\r
68     if (SingleBrushSelected)\r
69     {\r
70       Hll = vMin[0];\r
71       Vll = vMin[1];\r
72       Hur = vMax[0];\r
73       Vur = vMax[1];\r
74       Z00 = Z01 = Z10 = Z11 = vMax[2];\r
75     }\r
76     Generate = true;\r
77   }\r
78   else if (!strcmp (p, "Ceiling..."))\r
79   {\r
80     SingleBrushSelected = bSingleBrush;\r
81     Plane = PLANE_XY1;\r
82     if(SingleBrushSelected)\r
83     {\r
84       Hll = vMin[0];\r
85       Vll = vMin[1];\r
86       Hur = vMax[0];\r
87       Vur = vMax[1];\r
88       Z00 = Z01 = Z10 = Z11 = vMin[2];\r
89     }\r
90     Generate = true;\r
91   }\r
92   else if (!strcmp (p, "Wall facing 0..."))\r
93   {\r
94     SingleBrushSelected = bSingleBrush;\r
95     Plane = PLANE_YZ0;\r
96     if (SingleBrushSelected)\r
97     {\r
98       Hll = vMin[1];\r
99       Vll = vMin[2];\r
100       Hur = vMax[1];\r
101       Vur = vMax[2];\r
102       Z00 = Z01 = Z10 = Z11 = vMax[0];\r
103     }\r
104     Generate = true;\r
105   }\r
106   else if (!strcmp (p, "Wall facing 90..."))\r
107   {\r
108     SingleBrushSelected = bSingleBrush;\r
109     Plane = PLANE_XZ0;\r
110     if (SingleBrushSelected)\r
111     {\r
112       Hll = vMin[0];\r
113       Vll = vMin[2];\r
114       Hur = vMax[0];\r
115       Vur = vMax[2];\r
116       Z00 = Z01 = Z10 = Z11 = vMax[1];\r
117     }\r
118     Generate = true;\r
119   }\r
120   else if (!strcmp (p, "Wall facing 180..."))\r
121   {\r
122     SingleBrushSelected = bSingleBrush;\r
123     Plane = PLANE_YZ1;\r
124     if (SingleBrushSelected)\r
125     {\r
126       Hll = vMin[1];\r
127       Vll = vMin[2];\r
128       Hur = vMax[1];\r
129       Vur = vMax[2];\r
130       Z00 = Z01 = Z10 = Z11 = vMin[0];\r
131     }\r
132     Generate = true;\r
133   }\r
134   else if (!strcmp (p, "Wall facing 270..."))\r
135   {\r
136     SingleBrushSelected = bSingleBrush;\r
137     Plane = PLANE_XZ1;\r
138     if (SingleBrushSelected)\r
139     {\r
140       Hll = vMin[0];\r
141       Vll = vMin[2];\r
142       Hur = vMax[0];\r
143       Vur = vMax[2];\r
144       Z00 = Z01 = Z10 = Z11 = vMin[1];\r
145     }\r
146     Generate = true;\r
147   }\r
148   else if (!strcmp(p,"About..."))\r
149     About (g_pRadiantWnd);\r
150 \r
151   if (Generate)\r
152   {\r
153     if (SingleBrushSelected)\r
154       UseFaceBounds ();\r
155 \r
156     gtk_widget_show (g_pWnd);\r
157   }\r
158 }\r
159 \r
160 extern "C" LPVOID WINAPI QERPlug_GetFuncTable()\r
161 {\r
162   return &g_FuncTable;\r
163 }\r
164 \r
165 // =============================================================================\r
166 // SYNAPSE\r
167 \r
168 #include "synapse.h"\r
169 \r
170 class GenSurfSynapseClient : public CSynapseClient\r
171 {\r
172 public:\r
173   // CSynapseClient API\r
174   bool RequestAPI(APIDescriptor_t *pAPI);\r
175   const char* GetInfo();\r
176   \r
177   GenSurfSynapseClient() { }\r
178   virtual ~GenSurfSynapseClient() { }\r
179 };\r
180 \r
181 CSynapseServer* g_pSynapseServer = NULL;\r
182 GenSurfSynapseClient g_SynapseClient;\r
183 \r
184 extern "C" CSynapseClient* SYNAPSE_DLL_EXPORT Synapse_EnumerateInterfaces (const char *version, CSynapseServer *pServer)\r
185 {\r
186   if (strcmp(version, SYNAPSE_VERSION))\r
187   {\r
188     Syn_Printf("ERROR: synapse API version mismatch: should be '" SYNAPSE_VERSION "', got '%s'\n", version);\r
189     return NULL;\r
190   }\r
191   g_pSynapseServer = pServer;\r
192   g_pSynapseServer->IncRef();\r
193   Set_Syn_Printf(g_pSynapseServer->Get_Syn_Printf());\r
194 \r
195   g_SynapseClient.AddAPI(PLUGIN_MAJOR, "gtkgensurf", sizeof(_QERPluginTable));\r
196 \r
197   g_SynapseClient.AddAPI(RADIANT_MAJOR, NULL, sizeof(_QERFuncTable_1), SYN_REQUIRE, &g_FuncTable);\r
198   g_SynapseClient.AddAPI(UIGTK_MAJOR, NULL, sizeof(_QERUIGtkTable), SYN_REQUIRE, &g_UIGtkTable);\r
199   g_SynapseClient.AddAPI(QGL_MAJOR, NULL, sizeof(_QERQglTable), SYN_REQUIRE, &g_GLTable);\r
200   g_SynapseClient.AddAPI(ENTITY_MAJOR, NULL, sizeof(_QEREntityTable), SYN_REQUIRE, &g_EntityTable);\r
201 \r
202   return &g_SynapseClient;\r
203 }\r
204 \r
205 bool GenSurfSynapseClient::RequestAPI(APIDescriptor_t *pAPI)\r
206 {\r
207   if (!strcmp(pAPI->major_name, PLUGIN_MAJOR))\r
208   {\r
209     _QERPluginTable* pTable= static_cast<_QERPluginTable*>(pAPI->mpTable);\r
210 \r
211     pTable->m_pfnQERPlug_Init = QERPlug_Init;\r
212     pTable->m_pfnQERPlug_GetName = QERPlug_GetName;\r
213     pTable->m_pfnQERPlug_GetCommandList = QERPlug_GetCommandList;\r
214     pTable->m_pfnQERPlug_Dispatch = QERPlug_Dispatch;\r
215     return true;\r
216   }\r
217 \r
218   Syn_Printf("ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo());\r
219   return false;\r
220 }\r
221 \r
222 #include "version.h"\r
223 \r
224 const char* GenSurfSynapseClient::GetInfo()\r
225 {\r
226   return "GtkGenSurf - built " __DATE__ " " RADIANT_VERSION;\r
227 }\r