2 Copyright (C) 2003 Reed Mideke.
4 This file is part of GtkRadiant.
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.
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.
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
22 // 2d background Plugin
24 // Code by reyalP aka Reed Mideke
32 This little plugin allows you to display an image in the background of the
41 - three views, dialog box, toolbar
43 - tooltips, follow gtkradiant coding conventions
47 http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=88
52 - textures 'n widgets 'n stuff.
56 //TODO we just poke the objects directly
61 #define CMD_CONFIG "Configure..."
62 #define CMD_ABOUT "About..."
63 // =============================================================================
67 _QERFuncTable_1 g_FuncTable;
68 _QERQglTable g_QglTable;
69 _QERFileSystemTable g_FileSystemTable;
70 _QEREntityTable g_EntityTable;
71 _QERAppDataTable g_DataTable;
73 // for the file load dialog
76 // =============================================================================
77 // plugin implementation
79 static const char *PLUGIN_NAME = "2d window background plugin";
81 //backwards for some reason
82 static const char *PLUGIN_COMMANDS = CMD_ABOUT ";"
87 static const char *PLUGIN_ABOUT = "2d window background v0.25\n\n"
88 "By reyalP (hellsownpuppy@yahoo.com)";
93 void DoBkgrndToggleXY();
94 void DoBkgrndToggleXZ();
95 void DoBkgrndToggleYZ();
97 #define NUM_TOOLBAR_BUTTONS 4
98 struct toolbar_button_info_s
104 IToolbarButton::EType type;
107 struct toolbar_button_info_s toolbar_buttons[NUM_TOOLBAR_BUTTONS] =
110 "bkgrnd2d_xy_toggle.bmp",
112 "Toggle xy background image",
114 IToolbarButton::eToggleButton
117 "bkgrnd2d_xz_toggle.bmp",
119 "Toggle xz background image",
121 IToolbarButton::eToggleButton
124 "bkgrnd2d_yz_toggle.bmp",
126 "Toggle yz background image",
128 IToolbarButton::eToggleButton
133 "Configure background images",
134 ShowBackgroundDialog,
135 IToolbarButton::eButton
139 class Bkgrnd2dButton : public IToolbarButton
142 const toolbar_button_info_s *bi;
143 virtual const char* getImage() const
147 virtual const char* getText() const
151 virtual const char* getTooltip() const
155 virtual void activate() const
160 virtual EType getType() const
166 Bkgrnd2dButton g_bkgrnd2dbuttons[NUM_TOOLBAR_BUTTONS];
168 unsigned int ToolbarButtonCount()
170 return NUM_TOOLBAR_BUTTONS;
173 const IToolbarButton* GetToolbarButton(unsigned int index)
175 g_bkgrnd2dbuttons[index].bi = &toolbar_buttons[index];
176 return &g_bkgrnd2dbuttons[index];
179 extern "C" const char* QERPlug_Init (void *hApp, void* pMainWidget)
181 g_pMainWidget = pMainWidget;
183 InitBackgroundDialog();
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;
194 extern "C" const char* QERPlug_GetName ()
196 return (char *) PLUGIN_NAME;
199 extern "C" const char* QERPlug_GetCommandList ()
201 return (char *) PLUGIN_COMMANDS;
204 extern "C" void QERPlug_Dispatch (const char *p, vec3_t vMin, vec3_t vMax, bool bSingleBrush)
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);
210 else if(!strcmp(p,CMD_CONFIG)) {
211 ShowBackgroundDialog();
215 //TODO these three suck
216 void DoBkgrndToggleXY()
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);
227 g_FuncTable.m_pfnSysUpdateWindows(W_XY);
230 void DoBkgrndToggleXZ()
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);
237 g_FuncTable.m_pfnSysUpdateWindows(W_XY);
240 void DoBkgrndToggleYZ()
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);
247 g_FuncTable.m_pfnSysUpdateWindows(W_XY);
250 // =============================================================================
253 CSynapseServer* g_pSynapseServer = NULL;
254 CSynapseClientBkgrnd2d g_SynapseClient;
256 extern "C" CSynapseClient* SYNAPSE_DLL_EXPORT Synapse_EnumerateInterfaces (const char *version, CSynapseServer *pServer)
258 if (strcmp(version, SYNAPSE_VERSION))
260 Syn_Printf("ERROR: synapse API version mismatch: should be '" SYNAPSE_VERSION "', got '%s'\n", version);
263 g_pSynapseServer = pServer;
264 g_pSynapseServer->IncRef();
265 Set_Syn_Printf(g_pSynapseServer->Get_Syn_Printf());
267 g_SynapseClient.AddAPI(TOOLBAR_MAJOR, BKGRND2D_MINOR, sizeof(_QERPlugToolbarTable));
268 g_SynapseClient.AddAPI(PLUGIN_MAJOR, BKGRND2D_MINOR, sizeof( _QERPluginTable ) );
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 );
276 g_SynapseClient.AddAPI( ENTITY_MAJOR, NULL, sizeof( g_EntityTable ), SYN_REQUIRE, &g_EntityTable );
278 g_SynapseClient.AddAPI( DATA_MAJOR, NULL, sizeof( g_DataTable ), SYN_REQUIRE, &g_DataTable );
280 return &g_SynapseClient;
283 bool CSynapseClientBkgrnd2d::RequestAPI(APIDescriptor_t *pAPI)
285 if (!strcmp(pAPI->major_name, PLUGIN_MAJOR))
287 _QERPluginTable* pTable= static_cast<_QERPluginTable*>(pAPI->mpTable);
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;
295 if (!strcmp(pAPI->major_name, TOOLBAR_MAJOR))
297 _QERPlugToolbarTable* pTable= static_cast<_QERPlugToolbarTable*>(pAPI->mpTable);
299 pTable->m_pfnToolbarButtonCount = &ToolbarButtonCount;
300 pTable->m_pfnGetToolbarButton = &GetToolbarButton;
304 Syn_Printf("ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo());
310 const char* CSynapseClientBkgrnd2d::GetInfo()
312 return "2d Background plugin built " __DATE__ " " RADIANT_VERSION;
315 const char* CSynapseClientBkgrnd2d::GetName()