]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - contrib/bkgrnd2d/plugin.cpp
some updates to the Linux build system - obtained a core binary and all required...
[xonotic/netradiant.git] / contrib / bkgrnd2d / plugin.cpp
1 /*\r
2 Copyright (C) 1999-2007 id Software, Inc. and contributors.\r
3 For a list of contributors, see the accompanying CONTRIBUTORS file.\r
4 \r
5 This file is part of GtkRadiant.\r
6 \r
7 GtkRadiant is free software; you can redistribute it and/or modify\r
8 it under the terms of the GNU General Public License as published by\r
9 the Free Software Foundation; either version 2 of the License, or\r
10 (at your option) any later version.\r
11 \r
12 GtkRadiant is distributed in the hope that it will be useful,\r
13 but WITHOUT ANY WARRANTY; without even the implied warranty of\r
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
15 GNU General Public License for more details.\r
16 \r
17 You should have received a copy of the GNU General Public License\r
18 along with GtkRadiant; if not, write to the Free Software\r
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\r
20 */\r
21 \r
22 //\r
23 // 2d background Plugin\r
24 //\r
25 // Code by reyalP aka Reed Mideke\r
26 //\r
27 // Based on \r
28 //\r
29 \r
30 /*\r
31     Overview\r
32     ========\r
33         This little plugin allows you to display an image in the background of the\r
34         gtkradiant XY window.\r
35 \r
36     Version History\r
37     ===============\r
38 \r
39     v0.1\r
40       - Initial version.\r
41         v0.2\r
42           - three views, dialog box, toolbar\r
43     v0.25\r
44       - tooltips, follow gtkradiant coding conventions\r
45 \r
46     Why ?\r
47     -----\r
48       http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=88\r
49 \r
50 \r
51     How ?\r
52     -----\r
53      - textures 'n widgets 'n stuff.\r
54 */\r
55 \r
56 //#include "plugin.h"\r
57 //TODO we just poke the objects directly\r
58 #include "bkgrnd2d.h"\r
59 #include "dialog.h"\r
60 \r
61 #define CMD_SEP "-" \r
62 #define CMD_CONFIG "Configure..."\r
63 #define CMD_ABOUT "About..."\r
64 // =============================================================================\r
65 // Globals\r
66 \r
67 // function tables\r
68 _QERFuncTable_1 g_FuncTable;\r
69 _QERQglTable g_QglTable;\r
70 _QERFileSystemTable g_FileSystemTable;\r
71 _QEREntityTable g_EntityTable;\r
72 _QERAppDataTable g_DataTable;\r
73 \r
74 // for the file load dialog\r
75 void *g_pMainWidget;\r
76 \r
77 // =============================================================================\r
78 // plugin implementation\r
79 \r
80 static const char *PLUGIN_NAME = "2d window background plugin";\r
81 \r
82 //backwards for some reason\r
83 static const char *PLUGIN_COMMANDS = CMD_ABOUT ";" \r
84                                      CMD_SEP ";"\r
85                                                                                          CMD_CONFIG\r
86                                      ;\r
87 \r
88 static const char *PLUGIN_ABOUT = "2d window background v0.25\n\n"\r
89                                   "By reyalP (hellsownpuppy@yahoo.com)";\r
90 \r
91 \r
92 \r
93 \r
94 void DoBkgrndToggleXY();\r
95 void DoBkgrndToggleXZ();\r
96 void DoBkgrndToggleYZ();\r
97 \r
98 #define NUM_TOOLBAR_BUTTONS 4\r
99 struct toolbar_button_info_s\r
100 {\r
101         char *image;\r
102         char *text;\r
103         char *tip;\r
104         void (*func)();\r
105         IToolbarButton::EType type;\r
106 };\r
107 \r
108 struct toolbar_button_info_s toolbar_buttons[NUM_TOOLBAR_BUTTONS] = \r
109 {\r
110         {\r
111                 "bkgrnd2d_xy_toggle.bmp",\r
112                 "xy background",\r
113     "Toggle xy background image",\r
114                 DoBkgrndToggleXY,\r
115                 IToolbarButton::eToggleButton\r
116         },\r
117         {\r
118                 "bkgrnd2d_xz_toggle.bmp",\r
119                 "xz background",\r
120     "Toggle xz background image",\r
121                 DoBkgrndToggleXZ,\r
122                 IToolbarButton::eToggleButton\r
123         },\r
124         {\r
125                 "bkgrnd2d_yz_toggle.bmp",\r
126                 "yz background",\r
127     "Toggle yz background image",\r
128                 DoBkgrndToggleYZ,\r
129                 IToolbarButton::eToggleButton\r
130         },\r
131         {\r
132                 "bkgrnd2d_conf.bmp",\r
133                 "Configure",\r
134     "Configure background images",\r
135                 ShowBackgroundDialog,\r
136                 IToolbarButton::eButton\r
137         },\r
138 };\r
139 \r
140 class Bkgrnd2dButton : public IToolbarButton\r
141 {\r
142 public:\r
143   const toolbar_button_info_s *bi;\r
144   virtual const char* getImage() const\r
145   {\r
146     return bi->image;\r
147   }\r
148   virtual const char* getText() const\r
149   {\r
150     return bi->text;\r
151   }\r
152   virtual const char* getTooltip() const\r
153   {\r
154     return bi->tip;\r
155   }\r
156   virtual void activate() const\r
157   {\r
158     bi->func();\r
159     return ;\r
160   }\r
161   virtual EType getType() const\r
162   {\r
163     return bi->type;\r
164   }\r
165 };\r
166 \r
167 Bkgrnd2dButton g_bkgrnd2dbuttons[NUM_TOOLBAR_BUTTONS];\r
168 \r
169 unsigned int ToolbarButtonCount()\r
170 {\r
171   return NUM_TOOLBAR_BUTTONS;\r
172 }\r
173 \r
174 const IToolbarButton* GetToolbarButton(unsigned int index)\r
175 {\r
176   g_bkgrnd2dbuttons[index].bi = &toolbar_buttons[index];\r
177   return &g_bkgrnd2dbuttons[index];\r
178 }\r
179 \r
180 extern "C" const char* QERPlug_Init (void *hApp, void* pMainWidget)\r
181 {\r
182   g_pMainWidget = pMainWidget;\r
183 \r
184   InitBackgroundDialog();\r
185   render.Register();\r
186 \r
187 //TODO is it right ? is it wrong ? it works\r
188 //TODO figure out supported image types\r
189   GetFileTypeRegistry()->addType(FILETYPE_KEY, filetype_t("all files", "*.*"));\r
190   GetFileTypeRegistry()->addType(FILETYPE_KEY, filetype_t("jpeg files", "*.jpg"));\r
191   GetFileTypeRegistry()->addType(FILETYPE_KEY, filetype_t("targa files", "*.tga"));\r
192   return (char *) PLUGIN_NAME;\r
193 }\r
194 \r
195 extern "C" const char* QERPlug_GetName ()\r
196 {\r
197   return (char *) PLUGIN_NAME;\r
198 }\r
199 \r
200 extern "C" const char* QERPlug_GetCommandList ()\r
201 {\r
202   return (char *) PLUGIN_COMMANDS;\r
203 }\r
204 \r
205 extern "C" void QERPlug_Dispatch (const char *p, vec3_t vMin, vec3_t vMax, bool bSingleBrush)\r
206 {\r
207   Sys_Printf (MSG_PREFIX "Command \"%s\"\n",p); \r
208   if(!strcmp(p, CMD_ABOUT)) {\r
209         g_FuncTable.m_pfnMessageBox(NULL, PLUGIN_ABOUT, "About", MB_OK, NULL);\r
210   } \r
211   else if(!strcmp(p,CMD_CONFIG)) {\r
212         ShowBackgroundDialog();\r
213   }\r
214 }\r
215 \r
216 //TODO these three suck\r
217 void DoBkgrndToggleXY()\r
218 {\r
219   Sys_Printf (MSG_PREFIX "DoBkgrndToggleXY\n"); \r
220   // always toggle, since the buttons do\r
221   backgroundXY.m_bActive = (backgroundXY.m_bActive) ? false:true;\r
222   // if we don't have image or extents, and we activated,\r
223   // bring up the dialog with the corresponding page\r
224   // would be better to hide or grey out button, but we can't\r
225   if(backgroundXY.m_bActive && !backgroundXY.Valid())\r
226           ShowBackgroundDialogPG(0);\r
227   else\r
228           g_FuncTable.m_pfnSysUpdateWindows(W_XY);\r
229 }\r
230 \r
231 void DoBkgrndToggleXZ()\r
232 {\r
233   Sys_Printf (MSG_PREFIX "DoBkgrndToggleXZ\n"); \r
234   backgroundXZ.m_bActive = (backgroundXZ.m_bActive) ? false:true;\r
235   if(backgroundXZ.m_bActive && !backgroundXZ.Valid())\r
236           ShowBackgroundDialogPG(1);\r
237   else\r
238           g_FuncTable.m_pfnSysUpdateWindows(W_XY);\r
239 }\r
240 \r
241 void DoBkgrndToggleYZ()\r
242 {\r
243   Sys_Printf (MSG_PREFIX "DoBkgrndToggleYZ\n"); \r
244   backgroundYZ.m_bActive = (backgroundYZ.m_bActive) ? false:true;\r
245   if(backgroundYZ.m_bActive && !backgroundYZ.Valid())\r
246           ShowBackgroundDialogPG(2);\r
247   else\r
248           g_FuncTable.m_pfnSysUpdateWindows(W_XY);\r
249 }\r
250 \r
251 // =============================================================================\r
252 // SYNAPSE\r
253 \r
254 CSynapseServer* g_pSynapseServer = NULL;\r
255 CSynapseClientBkgrnd2d g_SynapseClient;\r
256     \r
257 #if __GNUC__ >= 4\r
258 #pragma GCC visibility push(default)\r
259 #endif\r
260 extern "C" CSynapseClient* SYNAPSE_DLL_EXPORT Synapse_EnumerateInterfaces( const char *version, CSynapseServer *pServer ) {\r
261 #if __GNUC__ >= 4\r
262 #pragma GCC visibility pop\r
263 #endif\r
264   if (strcmp(version, SYNAPSE_VERSION))\r
265   {\r
266     Syn_Printf("ERROR: synapse API version mismatch: should be '" SYNAPSE_VERSION "', got '%s'\n", version);\r
267     return NULL;\r
268   }\r
269   g_pSynapseServer = pServer;\r
270   g_pSynapseServer->IncRef();\r
271   Set_Syn_Printf(g_pSynapseServer->Get_Syn_Printf());\r
272 \r
273   g_SynapseClient.AddAPI(TOOLBAR_MAJOR, BKGRND2D_MINOR, sizeof(_QERPlugToolbarTable));\r
274   g_SynapseClient.AddAPI(PLUGIN_MAJOR, BKGRND2D_MINOR, sizeof( _QERPluginTable ) );\r
275 \r
276   g_SynapseClient.AddAPI( RADIANT_MAJOR, NULL, sizeof( g_FuncTable ), SYN_REQUIRE, &g_FuncTable );\r
277   g_SynapseClient.AddAPI( QGL_MAJOR, NULL, sizeof( g_QglTable ), SYN_REQUIRE, &g_QglTable );\r
278 // TODO is this the right way to ask for 'whichever VFS we have loaded' ? Seems to work\r
279 // for misc filename functions\r
280   g_SynapseClient.AddAPI( VFS_MAJOR, "*", sizeof( g_FileSystemTable ), SYN_REQUIRE, &g_FileSystemTable );\r
281 // get worldspawn\r
282   g_SynapseClient.AddAPI( ENTITY_MAJOR, NULL, sizeof( g_EntityTable ), SYN_REQUIRE, &g_EntityTable );\r
283 // selected brushes\r
284   g_SynapseClient.AddAPI( DATA_MAJOR, NULL, sizeof( g_DataTable ), SYN_REQUIRE, &g_DataTable );\r
285 \r
286   return &g_SynapseClient;\r
287 }\r
288 \r
289 bool CSynapseClientBkgrnd2d::RequestAPI(APIDescriptor_t *pAPI)\r
290 {\r
291   if (!strcmp(pAPI->major_name, PLUGIN_MAJOR))\r
292   {\r
293     _QERPluginTable* pTable= static_cast<_QERPluginTable*>(pAPI->mpTable);\r
294 \r
295     pTable->m_pfnQERPlug_Init = QERPlug_Init;\r
296     pTable->m_pfnQERPlug_GetName = QERPlug_GetName;\r
297     pTable->m_pfnQERPlug_GetCommandList = QERPlug_GetCommandList;\r
298     pTable->m_pfnQERPlug_Dispatch = QERPlug_Dispatch;\r
299     return true;\r
300   }\r
301   if (!strcmp(pAPI->major_name, TOOLBAR_MAJOR))\r
302   {\r
303     _QERPlugToolbarTable* pTable= static_cast<_QERPlugToolbarTable*>(pAPI->mpTable);\r
304 \r
305     pTable->m_pfnToolbarButtonCount = &ToolbarButtonCount;\r
306     pTable->m_pfnGetToolbarButton = &GetToolbarButton;\r
307     return true;\r
308   }\r
309 \r
310   Syn_Printf("ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo());\r
311   return false;\r
312 }\r
313 \r
314 #include "version.h"\r
315 \r
316 const char* CSynapseClientBkgrnd2d::GetInfo()\r
317 {\r
318   return "2d Background plugin built " __DATE__ " " RADIANT_VERSION;\r
319 }\r
320 \r
321 const char* CSynapseClientBkgrnd2d::GetName()\r
322 {\r
323   return "bkgrnd2d";\r
324 }\r
325 \r