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