2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
\r
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
\r
5 This file is part of GtkRadiant.
\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
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
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
23 // 2d background Plugin
\r
25 // Code by reyalP aka Reed Mideke
\r
33 This little plugin allows you to display an image in the background of the
\r
34 gtkradiant XY window.
\r
42 - three views, dialog box, toolbar
\r
44 - tooltips, follow gtkradiant coding conventions
\r
48 http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=88
\r
53 - textures 'n widgets 'n stuff.
\r
56 //#include "plugin.h"
\r
57 //TODO we just poke the objects directly
\r
58 #include "bkgrnd2d.h"
\r
61 #define CMD_SEP "-"
\r
62 #define CMD_CONFIG "Configure..."
\r
63 #define CMD_ABOUT "About..."
\r
64 // =============================================================================
\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
74 // for the file load dialog
\r
75 void *g_pMainWidget;
\r
77 // =============================================================================
\r
78 // plugin implementation
\r
80 static const char *PLUGIN_NAME = "2d window background plugin";
\r
82 //backwards for some reason
\r
83 static const char *PLUGIN_COMMANDS = CMD_ABOUT ";"
\r
88 static const char *PLUGIN_ABOUT = "2d window background v0.25\n\n"
\r
89 "By reyalP (hellsownpuppy@yahoo.com)";
\r
94 void DoBkgrndToggleXY();
\r
95 void DoBkgrndToggleXZ();
\r
96 void DoBkgrndToggleYZ();
\r
98 #define NUM_TOOLBAR_BUTTONS 4
\r
99 struct toolbar_button_info_s
\r
105 IToolbarButton::EType type;
\r
108 struct toolbar_button_info_s toolbar_buttons[NUM_TOOLBAR_BUTTONS] =
\r
111 "bkgrnd2d_xy_toggle.bmp",
\r
113 "Toggle xy background image",
\r
115 IToolbarButton::eToggleButton
\r
118 "bkgrnd2d_xz_toggle.bmp",
\r
120 "Toggle xz background image",
\r
122 IToolbarButton::eToggleButton
\r
125 "bkgrnd2d_yz_toggle.bmp",
\r
127 "Toggle yz background image",
\r
129 IToolbarButton::eToggleButton
\r
132 "bkgrnd2d_conf.bmp",
\r
134 "Configure background images",
\r
135 ShowBackgroundDialog,
\r
136 IToolbarButton::eButton
\r
140 class Bkgrnd2dButton : public IToolbarButton
\r
143 const toolbar_button_info_s *bi;
\r
144 virtual const char* getImage() const
\r
148 virtual const char* getText() const
\r
152 virtual const char* getTooltip() const
\r
156 virtual void activate() const
\r
161 virtual EType getType() const
\r
167 Bkgrnd2dButton g_bkgrnd2dbuttons[NUM_TOOLBAR_BUTTONS];
\r
169 unsigned int ToolbarButtonCount()
\r
171 return NUM_TOOLBAR_BUTTONS;
\r
174 const IToolbarButton* GetToolbarButton(unsigned int index)
\r
176 g_bkgrnd2dbuttons[index].bi = &toolbar_buttons[index];
\r
177 return &g_bkgrnd2dbuttons[index];
\r
180 extern "C" const char* QERPlug_Init (void *hApp, void* pMainWidget)
\r
182 g_pMainWidget = pMainWidget;
\r
184 InitBackgroundDialog();
\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
195 extern "C" const char* QERPlug_GetName ()
\r
197 return (char *) PLUGIN_NAME;
\r
200 extern "C" const char* QERPlug_GetCommandList ()
\r
202 return (char *) PLUGIN_COMMANDS;
\r
205 extern "C" void QERPlug_Dispatch (const char *p, vec3_t vMin, vec3_t vMax, bool bSingleBrush)
\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
211 else if(!strcmp(p,CMD_CONFIG)) {
\r
212 ShowBackgroundDialog();
\r
216 //TODO these three suck
\r
217 void DoBkgrndToggleXY()
\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
228 g_FuncTable.m_pfnSysUpdateWindows(W_XY);
\r
231 void DoBkgrndToggleXZ()
\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
238 g_FuncTable.m_pfnSysUpdateWindows(W_XY);
\r
241 void DoBkgrndToggleYZ()
\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
248 g_FuncTable.m_pfnSysUpdateWindows(W_XY);
\r
251 // =============================================================================
\r
254 CSynapseServer* g_pSynapseServer = NULL;
\r
255 CSynapseClientBkgrnd2d g_SynapseClient;
\r
258 #pragma GCC visibility push(default)
\r
260 extern "C" CSynapseClient* SYNAPSE_DLL_EXPORT Synapse_EnumerateInterfaces( const char *version, CSynapseServer *pServer ) {
\r
262 #pragma GCC visibility pop
\r
264 if (strcmp(version, SYNAPSE_VERSION))
\r
266 Syn_Printf("ERROR: synapse API version mismatch: should be '" SYNAPSE_VERSION "', got '%s'\n", version);
\r
269 g_pSynapseServer = pServer;
\r
270 g_pSynapseServer->IncRef();
\r
271 Set_Syn_Printf(g_pSynapseServer->Get_Syn_Printf());
\r
273 g_SynapseClient.AddAPI(TOOLBAR_MAJOR, BKGRND2D_MINOR, sizeof(_QERPlugToolbarTable));
\r
274 g_SynapseClient.AddAPI(PLUGIN_MAJOR, BKGRND2D_MINOR, sizeof( _QERPluginTable ) );
\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
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
286 return &g_SynapseClient;
\r
289 bool CSynapseClientBkgrnd2d::RequestAPI(APIDescriptor_t *pAPI)
\r
291 if (!strcmp(pAPI->major_name, PLUGIN_MAJOR))
\r
293 _QERPluginTable* pTable= static_cast<_QERPluginTable*>(pAPI->mpTable);
\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
301 if (!strcmp(pAPI->major_name, TOOLBAR_MAJOR))
\r
303 _QERPlugToolbarTable* pTable= static_cast<_QERPlugToolbarTable*>(pAPI->mpTable);
\r
305 pTable->m_pfnToolbarButtonCount = &ToolbarButtonCount;
\r
306 pTable->m_pfnGetToolbarButton = &GetToolbarButton;
\r
310 Syn_Printf("ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo());
\r
314 #include "version.h"
\r
316 const char* CSynapseClientBkgrnd2d::GetInfo()
\r
318 return "2d Background plugin built " __DATE__ " " RADIANT_VERSION;
\r
321 const char* CSynapseClientBkgrnd2d::GetName()
\r