2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 // 2d background Plugin
25 // Code by reyalP aka Reed Mideke
33 This little plugin allows you to display an image in the background of the
42 - three views, dialog box, toolbar
44 - tooltips, follow gtkradiant coding conventions
48 - textures 'n widgets 'n stuff.
52 //TODO we just poke the objects directly
57 #define CMD_CONFIG "Configure..."
58 #define CMD_ABOUT "About..."
59 // =============================================================================
63 _QERFuncTable_1 g_FuncTable;
64 _QERQglTable g_QglTable;
65 _QERFileSystemTable g_FileSystemTable;
66 _QEREntityTable g_EntityTable;
67 _QERAppDataTable g_DataTable;
69 // for the file load dialog
72 // =============================================================================
73 // plugin implementation
75 static const char *PLUGIN_NAME = "2d window background plugin";
77 //backwards for some reason
78 static const char *PLUGIN_COMMANDS = CMD_ABOUT ";"
83 static const char *PLUGIN_ABOUT = "2d window background v0.25\n\n"
84 "By reyalP (hellsownpuppy@yahoo.com)";
89 void DoBkgrndToggleXY();
90 void DoBkgrndToggleXZ();
91 void DoBkgrndToggleYZ();
93 #define NUM_TOOLBAR_BUTTONS 4
94 struct toolbar_button_info_s
100 IToolbarButton::EType type;
103 struct toolbar_button_info_s toolbar_buttons[NUM_TOOLBAR_BUTTONS] =
106 "bkgrnd2d_xy_toggle.bmp",
108 "Toggle xy background image",
110 IToolbarButton::eToggleButton
113 "bkgrnd2d_xz_toggle.bmp",
115 "Toggle xz background image",
117 IToolbarButton::eToggleButton
120 "bkgrnd2d_yz_toggle.bmp",
122 "Toggle yz background image",
124 IToolbarButton::eToggleButton
129 "Configure background images",
130 ShowBackgroundDialog,
131 IToolbarButton::eButton
135 class Bkgrnd2dButton : public IToolbarButton
138 const toolbar_button_info_s *bi;
139 virtual const char* getImage() const
143 virtual const char* getText() const
147 virtual const char* getTooltip() const
151 virtual void activate() const
156 virtual EType getType() const
162 Bkgrnd2dButton g_bkgrnd2dbuttons[NUM_TOOLBAR_BUTTONS];
164 unsigned int ToolbarButtonCount()
166 return NUM_TOOLBAR_BUTTONS;
169 const IToolbarButton* GetToolbarButton(unsigned int index)
171 g_bkgrnd2dbuttons[index].bi = &toolbar_buttons[index];
172 return &g_bkgrnd2dbuttons[index];
175 extern "C" const char* QERPlug_Init (void *hApp, void* pMainWidget)
177 g_pMainWidget = pMainWidget;
179 InitBackgroundDialog();
182 //TODO is it right ? is it wrong ? it works
183 //TODO figure out supported image types
184 GetFileTypeRegistry()->addType(FILETYPE_KEY, filetype_t("all files", "*.*"));
185 GetFileTypeRegistry()->addType(FILETYPE_KEY, filetype_t("jpeg files", "*.jpg"));
186 GetFileTypeRegistry()->addType(FILETYPE_KEY, filetype_t("targa files", "*.tga"));
187 return (char *) PLUGIN_NAME;
190 extern "C" const char* QERPlug_GetName ()
192 return (char *) PLUGIN_NAME;
195 extern "C" const char* QERPlug_GetCommandList ()
197 return (char *) PLUGIN_COMMANDS;
200 extern "C" void QERPlug_Dispatch (const char *p, vec3_t vMin, vec3_t vMax, bool bSingleBrush)
202 Sys_Printf (MSG_PREFIX "Command \"%s\"\n",p);
203 if(!strcmp(p, CMD_ABOUT)) {
204 g_FuncTable.m_pfnMessageBox(NULL, PLUGIN_ABOUT, "About", MB_OK, NULL);
206 else if(!strcmp(p,CMD_CONFIG)) {
207 ShowBackgroundDialog();
211 //TODO these three suck
212 void DoBkgrndToggleXY()
214 Sys_Printf (MSG_PREFIX "DoBkgrndToggleXY\n");
215 // always toggle, since the buttons do
216 backgroundXY.m_bActive = (backgroundXY.m_bActive) ? false:true;
217 // if we don't have image or extents, and we activated,
218 // bring up the dialog with the corresponding page
219 // would be better to hide or grey out button, but we can't
220 if(backgroundXY.m_bActive && !backgroundXY.Valid())
221 ShowBackgroundDialogPG(0);
223 g_FuncTable.m_pfnSysUpdateWindows(W_XY);
226 void DoBkgrndToggleXZ()
228 Sys_Printf (MSG_PREFIX "DoBkgrndToggleXZ\n");
229 backgroundXZ.m_bActive = (backgroundXZ.m_bActive) ? false:true;
230 if(backgroundXZ.m_bActive && !backgroundXZ.Valid())
231 ShowBackgroundDialogPG(1);
233 g_FuncTable.m_pfnSysUpdateWindows(W_XY);
236 void DoBkgrndToggleYZ()
238 Sys_Printf (MSG_PREFIX "DoBkgrndToggleYZ\n");
239 backgroundYZ.m_bActive = (backgroundYZ.m_bActive) ? false:true;
240 if(backgroundYZ.m_bActive && !backgroundYZ.Valid())
241 ShowBackgroundDialogPG(2);
243 g_FuncTable.m_pfnSysUpdateWindows(W_XY);
246 // =============================================================================
249 CSynapseServer* g_pSynapseServer = NULL;
250 CSynapseClientBkgrnd2d g_SynapseClient;
253 #pragma GCC visibility push(default)
255 extern "C" CSynapseClient* SYNAPSE_DLL_EXPORT Synapse_EnumerateInterfaces( const char *version, CSynapseServer *pServer ) {
257 #pragma GCC visibility pop
259 if (strcmp(version, SYNAPSE_VERSION))
261 Syn_Printf("ERROR: synapse API version mismatch: should be '" SYNAPSE_VERSION "', got '%s'\n", version);
264 g_pSynapseServer = pServer;
265 g_pSynapseServer->IncRef();
266 Set_Syn_Printf(g_pSynapseServer->Get_Syn_Printf());
268 g_SynapseClient.AddAPI(TOOLBAR_MAJOR, BKGRND2D_MINOR, sizeof(_QERPlugToolbarTable));
269 g_SynapseClient.AddAPI(PLUGIN_MAJOR, BKGRND2D_MINOR, sizeof( _QERPluginTable ) );
271 g_SynapseClient.AddAPI( RADIANT_MAJOR, NULL, sizeof( g_FuncTable ), SYN_REQUIRE, &g_FuncTable );
272 g_SynapseClient.AddAPI( QGL_MAJOR, NULL, sizeof( g_QglTable ), SYN_REQUIRE, &g_QglTable );
273 // TODO is this the right way to ask for 'whichever VFS we have loaded' ? Seems to work
274 // for misc filename functions
275 g_SynapseClient.AddAPI( VFS_MAJOR, "*", sizeof( g_FileSystemTable ), SYN_REQUIRE, &g_FileSystemTable );
277 g_SynapseClient.AddAPI( ENTITY_MAJOR, NULL, sizeof( g_EntityTable ), SYN_REQUIRE, &g_EntityTable );
279 g_SynapseClient.AddAPI( DATA_MAJOR, NULL, sizeof( g_DataTable ), SYN_REQUIRE, &g_DataTable );
281 return &g_SynapseClient;
284 bool CSynapseClientBkgrnd2d::RequestAPI(APIDescriptor_t *pAPI)
286 if (!strcmp(pAPI->major_name, PLUGIN_MAJOR))
288 _QERPluginTable* pTable= static_cast<_QERPluginTable*>(pAPI->mpTable);
290 pTable->m_pfnQERPlug_Init = QERPlug_Init;
291 pTable->m_pfnQERPlug_GetName = QERPlug_GetName;
292 pTable->m_pfnQERPlug_GetCommandList = QERPlug_GetCommandList;
293 pTable->m_pfnQERPlug_Dispatch = QERPlug_Dispatch;
296 if (!strcmp(pAPI->major_name, TOOLBAR_MAJOR))
298 _QERPlugToolbarTable* pTable= static_cast<_QERPlugToolbarTable*>(pAPI->mpTable);
300 pTable->m_pfnToolbarButtonCount = &ToolbarButtonCount;
301 pTable->m_pfnGetToolbarButton = &GetToolbarButton;
305 Syn_Printf("ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo());
311 const char* CSynapseClientBkgrnd2d::GetInfo()
313 return "2d Background plugin built " __DATE__ " " RADIANT_VERSION;
316 const char* CSynapseClientBkgrnd2d::GetName()