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.png",
112 "Toggle xy background image",
114 IToolbarButton::eToggleButton
117 "bkgrnd2d_xz_toggle.png",
119 "Toggle xz background image",
121 IToolbarButton::eToggleButton
124 "bkgrnd2d_yz_toggle.png",
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 {
146 virtual const char* getText() const {
149 virtual const char* getTooltip() const {
152 virtual void activate() const {
156 virtual EType getType() const {
161 Bkgrnd2dButton g_bkgrnd2dbuttons[NUM_TOOLBAR_BUTTONS];
163 unsigned int ToolbarButtonCount(){
164 return NUM_TOOLBAR_BUTTONS;
167 const IToolbarButton* GetToolbarButton( unsigned int index ){
168 g_bkgrnd2dbuttons[index].bi = &toolbar_buttons[index];
169 return &g_bkgrnd2dbuttons[index];
172 extern "C" const char* QERPlug_Init( void *hApp, void* pMainWidget ){
173 g_pMainWidget = pMainWidget;
175 InitBackgroundDialog();
178 //TODO is it right ? is it wrong ? it works
179 //TODO figure out supported image types
180 GetFileTypeRegistry()->addType( FILETYPE_KEY, filetype_t( "all files", "*.*" ) );
181 GetFileTypeRegistry()->addType( FILETYPE_KEY, filetype_t( "jpeg files", "*.jpg" ) );
182 GetFileTypeRegistry()->addType( FILETYPE_KEY, filetype_t( "targa files", "*.tga" ) );
183 return (char *) PLUGIN_NAME;
186 extern "C" const char* QERPlug_GetName(){
187 return (char *) PLUGIN_NAME;
190 extern "C" const char* QERPlug_GetCommandList(){
191 return (char *) PLUGIN_COMMANDS;
194 extern "C" void QERPlug_Dispatch( const char *p, vec3_t vMin, vec3_t vMax, bool bSingleBrush ){
195 Sys_Printf( MSG_PREFIX "Command \"%s\"\n",p );
196 if ( !strcmp( p, CMD_ABOUT ) ) {
197 g_FuncTable.m_pfnMessageBox( NULL, PLUGIN_ABOUT, "About", MB_OK, NULL );
199 else if ( !strcmp( p,CMD_CONFIG ) ) {
200 ShowBackgroundDialog();
204 //TODO these three suck
205 void DoBkgrndToggleXY(){
206 Sys_Printf( MSG_PREFIX "DoBkgrndToggleXY\n" );
207 // always toggle, since the buttons do
208 backgroundXY.m_bActive = ( backgroundXY.m_bActive ) ? false : true;
209 // if we don't have image or extents, and we activated,
210 // bring up the dialog with the corresponding page
211 // would be better to hide or grey out button, but we can't
212 if ( backgroundXY.m_bActive && !backgroundXY.Valid() ) {
213 ShowBackgroundDialogPG( 0 );
216 g_FuncTable.m_pfnSysUpdateWindows( W_XY );
220 void DoBkgrndToggleXZ(){
221 Sys_Printf( MSG_PREFIX "DoBkgrndToggleXZ\n" );
222 backgroundXZ.m_bActive = ( backgroundXZ.m_bActive ) ? false : true;
223 if ( backgroundXZ.m_bActive && !backgroundXZ.Valid() ) {
224 ShowBackgroundDialogPG( 1 );
227 g_FuncTable.m_pfnSysUpdateWindows( W_XY );
231 void DoBkgrndToggleYZ(){
232 Sys_Printf( MSG_PREFIX "DoBkgrndToggleYZ\n" );
233 backgroundYZ.m_bActive = ( backgroundYZ.m_bActive ) ? false : true;
234 if ( backgroundYZ.m_bActive && !backgroundYZ.Valid() ) {
235 ShowBackgroundDialogPG( 2 );
238 g_FuncTable.m_pfnSysUpdateWindows( W_XY );
242 // =============================================================================
245 CSynapseServer* g_pSynapseServer = NULL;
246 CSynapseClientBkgrnd2d g_SynapseClient;
248 extern "C" CSynapseClient * SYNAPSE_DLL_EXPORT Synapse_EnumerateInterfaces( const char *version, CSynapseServer *pServer ){
249 if ( strcmp( version, SYNAPSE_VERSION ) ) {
250 Syn_Printf( "ERROR: synapse API version mismatch: should be '" SYNAPSE_VERSION "', got '%s'\n", version );
253 g_pSynapseServer = pServer;
254 g_pSynapseServer->IncRef();
255 Set_Syn_Printf( g_pSynapseServer->Get_Syn_Printf() );
257 g_SynapseClient.AddAPI( TOOLBAR_MAJOR, BKGRND2D_MINOR, sizeof( _QERPlugToolbarTable ) );
258 g_SynapseClient.AddAPI( PLUGIN_MAJOR, BKGRND2D_MINOR, sizeof( _QERPluginTable ) );
260 g_SynapseClient.AddAPI( RADIANT_MAJOR, NULL, sizeof( g_FuncTable ), SYN_REQUIRE, &g_FuncTable );
261 g_SynapseClient.AddAPI( QGL_MAJOR, NULL, sizeof( g_QglTable ), SYN_REQUIRE, &g_QglTable );
262 // TODO is this the right way to ask for 'whichever VFS we have loaded' ? Seems to work
263 // for misc filename functions
264 g_SynapseClient.AddAPI( VFS_MAJOR, "*", sizeof( g_FileSystemTable ), SYN_REQUIRE, &g_FileSystemTable );
266 g_SynapseClient.AddAPI( ENTITY_MAJOR, NULL, sizeof( g_EntityTable ), SYN_REQUIRE, &g_EntityTable );
268 g_SynapseClient.AddAPI( DATA_MAJOR, NULL, sizeof( g_DataTable ), SYN_REQUIRE, &g_DataTable );
270 return &g_SynapseClient;
273 bool CSynapseClientBkgrnd2d::RequestAPI( APIDescriptor_t *pAPI ){
274 if ( !strcmp( pAPI->major_name, PLUGIN_MAJOR ) ) {
275 _QERPluginTable* pTable = static_cast<_QERPluginTable*>( pAPI->mpTable );
277 pTable->m_pfnQERPlug_Init = QERPlug_Init;
278 pTable->m_pfnQERPlug_GetName = QERPlug_GetName;
279 pTable->m_pfnQERPlug_GetCommandList = QERPlug_GetCommandList;
280 pTable->m_pfnQERPlug_Dispatch = QERPlug_Dispatch;
283 if ( !strcmp( pAPI->major_name, TOOLBAR_MAJOR ) ) {
284 _QERPlugToolbarTable* pTable = static_cast<_QERPlugToolbarTable*>( pAPI->mpTable );
286 pTable->m_pfnToolbarButtonCount = &ToolbarButtonCount;
287 pTable->m_pfnGetToolbarButton = &GetToolbarButton;
291 Syn_Printf( "ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo() );
297 const char* CSynapseClientBkgrnd2d::GetInfo(){
298 return "2d Background plugin built " __DATE__ " " RADIANT_VERSION;
301 const char* CSynapseClientBkgrnd2d::GetName(){