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 ";"
86 static const char *PLUGIN_ABOUT = "2d window background v0.25\n\n"
87 "By reyalP (hellsownpuppy@yahoo.com)";
90 void DoBkgrndToggleXY();
92 void DoBkgrndToggleXZ();
94 void DoBkgrndToggleYZ();
96 #define NUM_TOOLBAR_BUTTONS 4
98 struct toolbar_button_info_s {
105 IToolbarButton::EType type;
108 struct toolbar_button_info_s toolbar_buttons[NUM_TOOLBAR_BUTTONS] =
111 "bkgrnd2d_xy_toggle.png",
113 "Toggle xy background image",
115 IToolbarButton::eToggleButton
118 "bkgrnd2d_xz_toggle.png",
120 "Toggle xz background image",
122 IToolbarButton::eToggleButton
125 "bkgrnd2d_yz_toggle.png",
127 "Toggle yz background image",
129 IToolbarButton::eToggleButton
134 "Configure background images",
135 ShowBackgroundDialog,
136 IToolbarButton::eButton
140 class Bkgrnd2dButton : public IToolbarButton {
142 const toolbar_button_info_s *bi;
144 virtual const char *getImage() const
149 virtual const char *getText() const
154 virtual const char *getTooltip() const
159 virtual void activate() const
165 virtual EType getType() const
171 Bkgrnd2dButton g_bkgrnd2dbuttons[NUM_TOOLBAR_BUTTONS];
173 unsigned int ToolbarButtonCount()
175 return NUM_TOOLBAR_BUTTONS;
178 const IToolbarButton *GetToolbarButton(unsigned int index)
180 g_bkgrnd2dbuttons[index].bi = &toolbar_buttons[index];
181 return &g_bkgrnd2dbuttons[index];
184 extern "C" const char *QERPlug_Init(void *hApp, void *pMainWidget)
186 g_pMainWidget = pMainWidget;
188 InitBackgroundDialog();
191 //TODO is it right ? is it wrong ? it works
192 //TODO figure out supported image types
193 GetFileTypeRegistry()->addType(FILETYPE_KEY, filetype_t("all files", "*.*"));
194 GetFileTypeRegistry()->addType(FILETYPE_KEY, filetype_t("jpeg files", "*.jpg"));
195 GetFileTypeRegistry()->addType(FILETYPE_KEY, filetype_t("targa files", "*.tga"));
196 return (char *) PLUGIN_NAME;
199 extern "C" const char *QERPlug_GetName()
201 return (char *) PLUGIN_NAME;
204 extern "C" const char *QERPlug_GetCommandList()
206 return (char *) PLUGIN_COMMANDS;
209 extern "C" void QERPlug_Dispatch(const char *p, vec3_t vMin, vec3_t vMax, bool bSingleBrush)
211 Sys_Printf(MSG_PREFIX "Command \"%s\"\n", p);
212 if (!strcmp(p, CMD_ABOUT)) {
213 g_FuncTable.m_pfnMessageBox(NULL, PLUGIN_ABOUT, "About", MB_OK, NULL);
214 } else if (!strcmp(p, CMD_CONFIG)) {
215 ShowBackgroundDialog();
219 //TODO these three suck
220 void DoBkgrndToggleXY()
222 Sys_Printf(MSG_PREFIX "DoBkgrndToggleXY\n");
223 // always toggle, since the buttons do
224 backgroundXY.m_bActive = (backgroundXY.m_bActive) ? false : true;
225 // if we don't have image or extents, and we activated,
226 // bring up the dialog with the corresponding page
227 // would be better to hide or grey out button, but we can't
228 if (backgroundXY.m_bActive && !backgroundXY.Valid()) {
229 ShowBackgroundDialogPG(0);
231 g_FuncTable.m_pfnSysUpdateWindows(W_XY);
235 void DoBkgrndToggleXZ()
237 Sys_Printf(MSG_PREFIX "DoBkgrndToggleXZ\n");
238 backgroundXZ.m_bActive = (backgroundXZ.m_bActive) ? false : true;
239 if (backgroundXZ.m_bActive && !backgroundXZ.Valid()) {
240 ShowBackgroundDialogPG(1);
242 g_FuncTable.m_pfnSysUpdateWindows(W_XY);
246 void DoBkgrndToggleYZ()
248 Sys_Printf(MSG_PREFIX "DoBkgrndToggleYZ\n");
249 backgroundYZ.m_bActive = (backgroundYZ.m_bActive) ? false : true;
250 if (backgroundYZ.m_bActive && !backgroundYZ.Valid()) {
251 ShowBackgroundDialogPG(2);
253 g_FuncTable.m_pfnSysUpdateWindows(W_XY);
257 // =============================================================================
260 CSynapseServer *g_pSynapseServer = NULL;
261 CSynapseClientBkgrnd2d g_SynapseClient;
263 extern "C" CSynapseClient *SYNAPSE_DLL_EXPORT
265 Synapse_EnumerateInterfaces(const char *version, CSynapseServer *pServer)
267 if (strcmp(version, SYNAPSE_VERSION)) {
268 Syn_Printf("ERROR: synapse API version mismatch: should be '"
270 "', got '%s'\n", version );
273 g_pSynapseServer = pServer;
274 g_pSynapseServer->IncRef();
275 Set_Syn_Printf(g_pSynapseServer->Get_Syn_Printf());
277 g_SynapseClient.AddAPI(TOOLBAR_MAJOR, BKGRND2D_MINOR, sizeof(_QERPlugToolbarTable));
278 g_SynapseClient.AddAPI(PLUGIN_MAJOR, BKGRND2D_MINOR, sizeof(_QERPluginTable));
280 g_SynapseClient.AddAPI(RADIANT_MAJOR, NULL, sizeof(g_FuncTable), SYN_REQUIRE, &g_FuncTable);
281 g_SynapseClient.AddAPI(QGL_MAJOR, NULL, sizeof(g_QglTable), SYN_REQUIRE, &g_QglTable);
282 // TODO is this the right way to ask for 'whichever VFS we have loaded' ? Seems to work
283 // for misc filename functions
284 g_SynapseClient.AddAPI(VFS_MAJOR, "*", sizeof(g_FileSystemTable), SYN_REQUIRE, &g_FileSystemTable);
286 g_SynapseClient.AddAPI(ENTITY_MAJOR, NULL, sizeof(g_EntityTable), SYN_REQUIRE, &g_EntityTable);
288 g_SynapseClient.AddAPI(DATA_MAJOR, NULL, sizeof(g_DataTable), SYN_REQUIRE, &g_DataTable);
290 return &g_SynapseClient;
293 bool CSynapseClientBkgrnd2d::RequestAPI(APIDescriptor_t *pAPI)
295 if (!strcmp(pAPI->major_name, PLUGIN_MAJOR)) {
296 _QERPluginTable *pTable = static_cast<_QERPluginTable *>( pAPI->mpTable );
298 pTable->m_pfnQERPlug_Init = QERPlug_Init;
299 pTable->m_pfnQERPlug_GetName = QERPlug_GetName;
300 pTable->m_pfnQERPlug_GetCommandList = QERPlug_GetCommandList;
301 pTable->m_pfnQERPlug_Dispatch = QERPlug_Dispatch;
304 if (!strcmp(pAPI->major_name, TOOLBAR_MAJOR)) {
305 _QERPlugToolbarTable *pTable = static_cast<_QERPlugToolbarTable *>( pAPI->mpTable );
307 pTable->m_pfnToolbarButtonCount = &ToolbarButtonCount;
308 pTable->m_pfnGetToolbarButton = &GetToolbarButton;
312 Syn_Printf("ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo());
318 const char *CSynapseClientBkgrnd2d::GetInfo()
320 return "2d Background plugin built " __DATE__ " "
324 const char *CSynapseClientBkgrnd2d::GetName()