]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - contrib/bkgrnd2d/plugin.cpp
- Radiant is now Vista compatible (Aero must be disabled)
[xonotic/netradiant.git] / contrib / bkgrnd2d / plugin.cpp
index ce27430fd368d39df7aa0047a50f61a55c919661..09e9ed7c8f92be2d068802b6437135b9afd87402 100644 (file)
-/*\r
-Copyright (C) 2003 Reed Mideke.\r
-\r
-This file is part of GtkRadiant.\r
-\r
-GtkRadiant is free software; you can redistribute it and/or modify\r
-it under the terms of the GNU General Public License as published by\r
-the Free Software Foundation; either version 2 of the License, or\r
-(at your option) any later version.\r
-\r
-GtkRadiant is distributed in the hope that it will be useful,\r
-but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
-GNU General Public License for more details.\r
-\r
-You should have received a copy of the GNU General Public License\r
-along with GtkRadiant; if not, write to the Free Software\r
-Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\r
-*/\r
-\r
-//\r
-// 2d background Plugin\r
-//\r
-// Code by reyalP aka Reed Mideke\r
-//\r
-// Based on \r
-//\r
-\r
-/*\r
-    Overview\r
-    ========\r
-       This little plugin allows you to display an image in the background of the\r
-       gtkradiant XY window.\r
-\r
-    Version History\r
-    ===============\r
-\r
-    v0.1\r
-      - Initial version.\r
-       v0.2\r
-         - three views, dialog box, toolbar\r
-    v0.25\r
-      - tooltips, follow gtkradiant coding conventions\r
-\r
-    Why ?\r
-    -----\r
-      http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=88\r
-\r
-\r
-    How ?\r
-    -----\r
-     - textures 'n widgets 'n stuff.\r
-*/\r
-\r
-//#include "plugin.h"\r
-//TODO we just poke the objects directly\r
-#include "bkgrnd2d.h"\r
-#include "dialog.h"\r
-\r
-#define CMD_SEP "-" \r
-#define CMD_CONFIG "Configure..."\r
-#define CMD_ABOUT "About..."\r
-// =============================================================================\r
-// Globals\r
-\r
-// function tables\r
-_QERFuncTable_1 g_FuncTable;\r
-_QERQglTable g_QglTable;\r
-_QERFileSystemTable g_FileSystemTable;\r
-_QEREntityTable g_EntityTable;\r
-_QERAppDataTable g_DataTable;\r
-\r
-// for the file load dialog\r
-void *g_pMainWidget;\r
-\r
-// =============================================================================\r
-// plugin implementation\r
-\r
-static const char *PLUGIN_NAME = "2d window background plugin";\r
-\r
-//backwards for some reason\r
-static const char *PLUGIN_COMMANDS = CMD_ABOUT ";" \r
-                                     CMD_SEP ";"\r
-                                                                                        CMD_CONFIG\r
-                                     ;\r
-\r
-static const char *PLUGIN_ABOUT = "2d window background v0.25\n\n"\r
-                                  "By reyalP (hellsownpuppy@yahoo.com)";\r
-\r
-\r
-\r
-\r
-void DoBkgrndToggleXY();\r
-void DoBkgrndToggleXZ();\r
-void DoBkgrndToggleYZ();\r
-\r
-#define NUM_TOOLBAR_BUTTONS 4\r
-struct toolbar_button_info_s\r
-{\r
-       char *image;\r
-       char *text;\r
-       char *tip;\r
-       void (*func)();\r
-       IToolbarButton::EType type;\r
-};\r
-\r
-struct toolbar_button_info_s toolbar_buttons[NUM_TOOLBAR_BUTTONS] = \r
-{\r
-       {\r
-               "bkgrnd2d_xy_toggle.bmp",\r
-               "xy background",\r
-    "Toggle xy background image",\r
-               DoBkgrndToggleXY,\r
-               IToolbarButton::eToggleButton\r
-       },\r
-       {\r
-               "bkgrnd2d_xz_toggle.bmp",\r
-               "xz background",\r
-    "Toggle xz background image",\r
-               DoBkgrndToggleXZ,\r
-               IToolbarButton::eToggleButton\r
-       },\r
-       {\r
-               "bkgrnd2d_yz_toggle.bmp",\r
-               "yz background",\r
-    "Toggle yz background image",\r
-               DoBkgrndToggleYZ,\r
-               IToolbarButton::eToggleButton\r
-       },\r
-       {\r
-               "bkgrnd2d_conf.bmp",\r
-               "Configure",\r
-    "Configure background images",\r
-               ShowBackgroundDialog,\r
-               IToolbarButton::eButton\r
-       },\r
-};\r
-\r
-class Bkgrnd2dButton : public IToolbarButton\r
-{\r
-public:\r
-  const toolbar_button_info_s *bi;\r
-  virtual const char* getImage() const\r
-  {\r
-    return bi->image;\r
-  }\r
-  virtual const char* getText() const\r
-  {\r
-    return bi->text;\r
-  }\r
-  virtual const char* getTooltip() const\r
-  {\r
-    return bi->tip;\r
-  }\r
-  virtual void activate() const\r
-  {\r
-    bi->func();\r
-    return ;\r
-  }\r
-  virtual EType getType() const\r
-  {\r
-    return bi->type;\r
-  }\r
-};\r
-\r
-Bkgrnd2dButton g_bkgrnd2dbuttons[NUM_TOOLBAR_BUTTONS];\r
-\r
-unsigned int ToolbarButtonCount()\r
-{\r
-  return NUM_TOOLBAR_BUTTONS;\r
-}\r
-\r
-const IToolbarButton* GetToolbarButton(unsigned int index)\r
-{\r
-  g_bkgrnd2dbuttons[index].bi = &toolbar_buttons[index];\r
-  return &g_bkgrnd2dbuttons[index];\r
-}\r
-\r
-extern "C" const char* QERPlug_Init (void *hApp, void* pMainWidget)\r
-{\r
-  g_pMainWidget = pMainWidget;\r
-\r
-  InitBackgroundDialog();\r
-  render.Register();\r
-\r
-//TODO is it right ? is it wrong ? it works\r
-//TODO figure out supported image types\r
-  GetFileTypeRegistry()->addType(FILETYPE_KEY, filetype_t("all files", "*.*"));\r
-  GetFileTypeRegistry()->addType(FILETYPE_KEY, filetype_t("jpeg files", "*.jpg"));\r
-  GetFileTypeRegistry()->addType(FILETYPE_KEY, filetype_t("targa files", "*.tga"));\r
-  return (char *) PLUGIN_NAME;\r
-}\r
-\r
-extern "C" const char* QERPlug_GetName ()\r
-{\r
-  return (char *) PLUGIN_NAME;\r
-}\r
-\r
-extern "C" const char* QERPlug_GetCommandList ()\r
-{\r
-  return (char *) PLUGIN_COMMANDS;\r
-}\r
-\r
-extern "C" void QERPlug_Dispatch (const char *p, vec3_t vMin, vec3_t vMax, bool bSingleBrush)\r
-{\r
-  Sys_Printf (MSG_PREFIX "Command \"%s\"\n",p); \r
-  if(!strcmp(p, CMD_ABOUT)) {\r
-       g_FuncTable.m_pfnMessageBox(NULL, PLUGIN_ABOUT, "About", MB_OK, NULL);\r
-  } \r
-  else if(!strcmp(p,CMD_CONFIG)) {\r
-       ShowBackgroundDialog();\r
-  }\r
-}\r
-\r
-//TODO these three suck\r
-void DoBkgrndToggleXY()\r
-{\r
-  Sys_Printf (MSG_PREFIX "DoBkgrndToggleXY\n"); \r
-  // always toggle, since the buttons do\r
-  backgroundXY.m_bActive = (backgroundXY.m_bActive) ? false:true;\r
-  // if we don't have image or extents, and we activated,\r
-  // bring up the dialog with the corresponding page\r
-  // would be better to hide or grey out button, but we can't\r
-  if(backgroundXY.m_bActive && !backgroundXY.Valid())\r
-         ShowBackgroundDialogPG(0);\r
-  else\r
-         g_FuncTable.m_pfnSysUpdateWindows(W_XY);\r
-}\r
-\r
-void DoBkgrndToggleXZ()\r
-{\r
-  Sys_Printf (MSG_PREFIX "DoBkgrndToggleXZ\n"); \r
-  backgroundXZ.m_bActive = (backgroundXZ.m_bActive) ? false:true;\r
-  if(backgroundXZ.m_bActive && !backgroundXZ.Valid())\r
-         ShowBackgroundDialogPG(1);\r
-  else\r
-         g_FuncTable.m_pfnSysUpdateWindows(W_XY);\r
-}\r
-\r
-void DoBkgrndToggleYZ()\r
-{\r
-  Sys_Printf (MSG_PREFIX "DoBkgrndToggleYZ\n"); \r
-  backgroundYZ.m_bActive = (backgroundYZ.m_bActive) ? false:true;\r
-  if(backgroundYZ.m_bActive && !backgroundYZ.Valid())\r
-         ShowBackgroundDialogPG(2);\r
-  else\r
-         g_FuncTable.m_pfnSysUpdateWindows(W_XY);\r
-}\r
-\r
-// =============================================================================\r
-// SYNAPSE\r
-\r
-CSynapseServer* g_pSynapseServer = NULL;\r
-CSynapseClientBkgrnd2d g_SynapseClient;\r
-    \r
-extern "C" CSynapseClient* SYNAPSE_DLL_EXPORT Synapse_EnumerateInterfaces (const char *version, CSynapseServer *pServer)\r
-{\r
-  if (strcmp(version, SYNAPSE_VERSION))\r
-  {\r
-    Syn_Printf("ERROR: synapse API version mismatch: should be '" SYNAPSE_VERSION "', got '%s'\n", version);\r
-    return NULL;\r
-  }\r
-  g_pSynapseServer = pServer;\r
-  g_pSynapseServer->IncRef();\r
-  Set_Syn_Printf(g_pSynapseServer->Get_Syn_Printf());\r
-\r
-  g_SynapseClient.AddAPI(TOOLBAR_MAJOR, BKGRND2D_MINOR, sizeof(_QERPlugToolbarTable));\r
-  g_SynapseClient.AddAPI(PLUGIN_MAJOR, BKGRND2D_MINOR, sizeof( _QERPluginTable ) );\r
-\r
-  g_SynapseClient.AddAPI( RADIANT_MAJOR, NULL, sizeof( g_FuncTable ), SYN_REQUIRE, &g_FuncTable );\r
-  g_SynapseClient.AddAPI( QGL_MAJOR, NULL, sizeof( g_QglTable ), SYN_REQUIRE, &g_QglTable );\r
-// TODO is this the right way to ask for 'whichever VFS we have loaded' ? Seems to work\r
-// for misc filename functions\r
-  g_SynapseClient.AddAPI( VFS_MAJOR, "*", sizeof( g_FileSystemTable ), SYN_REQUIRE, &g_FileSystemTable );\r
-// get worldspawn\r
-  g_SynapseClient.AddAPI( ENTITY_MAJOR, NULL, sizeof( g_EntityTable ), SYN_REQUIRE, &g_EntityTable );\r
-// selected brushes\r
-  g_SynapseClient.AddAPI( DATA_MAJOR, NULL, sizeof( g_DataTable ), SYN_REQUIRE, &g_DataTable );\r
-\r
-  return &g_SynapseClient;\r
-}\r
-\r
-bool CSynapseClientBkgrnd2d::RequestAPI(APIDescriptor_t *pAPI)\r
-{\r
-  if (!strcmp(pAPI->major_name, PLUGIN_MAJOR))\r
-  {\r
-    _QERPluginTable* pTable= static_cast<_QERPluginTable*>(pAPI->mpTable);\r
-\r
-    pTable->m_pfnQERPlug_Init = QERPlug_Init;\r
-    pTable->m_pfnQERPlug_GetName = QERPlug_GetName;\r
-    pTable->m_pfnQERPlug_GetCommandList = QERPlug_GetCommandList;\r
-    pTable->m_pfnQERPlug_Dispatch = QERPlug_Dispatch;\r
-    return true;\r
-  }\r
-  if (!strcmp(pAPI->major_name, TOOLBAR_MAJOR))\r
-  {\r
-    _QERPlugToolbarTable* pTable= static_cast<_QERPlugToolbarTable*>(pAPI->mpTable);\r
-\r
-    pTable->m_pfnToolbarButtonCount = &ToolbarButtonCount;\r
-    pTable->m_pfnGetToolbarButton = &GetToolbarButton;\r
-    return true;\r
-  }\r
-\r
-  Syn_Printf("ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo());\r
-  return false;\r
-}\r
-\r
-#include "version.h"\r
-\r
-const char* CSynapseClientBkgrnd2d::GetInfo()\r
-{\r
-  return "2d Background plugin built " __DATE__ " " RADIANT_VERSION;\r
-}\r
-\r
-const char* CSynapseClientBkgrnd2d::GetName()\r
-{\r
-  return "bkgrnd2d";\r
-}\r
-\r
+/*
+Copyright (C) 2003 Reed Mideke.
+
+This file is part of GtkRadiant.
+
+GtkRadiant is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+GtkRadiant is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GtkRadiant; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+//
+// 2d background Plugin
+//
+// Code by reyalP aka Reed Mideke
+//
+// Based on 
+//
+
+/*
+    Overview
+    ========
+       This little plugin allows you to display an image in the background of the
+       gtkradiant XY window.
+
+    Version History
+    ===============
+
+    v0.1
+      - Initial version.
+       v0.2
+         - three views, dialog box, toolbar
+    v0.25
+      - tooltips, follow gtkradiant coding conventions
+
+    Why ?
+    -----
+      http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=88
+
+
+    How ?
+    -----
+     - textures 'n widgets 'n stuff.
+*/
+
+//#include "plugin.h"
+//TODO we just poke the objects directly
+#include "bkgrnd2d.h"
+#include "dialog.h"
+
+#define CMD_SEP "-" 
+#define CMD_CONFIG "Configure..."
+#define CMD_ABOUT "About..."
+// =============================================================================
+// Globals
+
+// function tables
+_QERFuncTable_1 g_FuncTable;
+_QERQglTable g_QglTable;
+_QERFileSystemTable g_FileSystemTable;
+_QEREntityTable g_EntityTable;
+_QERAppDataTable g_DataTable;
+
+// for the file load dialog
+void *g_pMainWidget;
+
+// =============================================================================
+// plugin implementation
+
+static const char *PLUGIN_NAME = "2d window background plugin";
+
+//backwards for some reason
+static const char *PLUGIN_COMMANDS = CMD_ABOUT ";" 
+                                     CMD_SEP ";"
+                                                                                        CMD_CONFIG
+                                     ;
+
+static const char *PLUGIN_ABOUT = "2d window background v0.25\n\n"
+                                  "By reyalP (hellsownpuppy@yahoo.com)";
+
+
+
+
+void DoBkgrndToggleXY();
+void DoBkgrndToggleXZ();
+void DoBkgrndToggleYZ();
+
+#define NUM_TOOLBAR_BUTTONS 4
+struct toolbar_button_info_s
+{
+       char *image;
+       char *text;
+       char *tip;
+       void (*func)();
+       IToolbarButton::EType type;
+};
+
+struct toolbar_button_info_s toolbar_buttons[NUM_TOOLBAR_BUTTONS] = 
+{
+       {
+               "bkgrnd2d_xy_toggle.bmp",
+               "xy background",
+    "Toggle xy background image",
+               DoBkgrndToggleXY,
+               IToolbarButton::eToggleButton
+       },
+       {
+               "bkgrnd2d_xz_toggle.bmp",
+               "xz background",
+    "Toggle xz background image",
+               DoBkgrndToggleXZ,
+               IToolbarButton::eToggleButton
+       },
+       {
+               "bkgrnd2d_yz_toggle.bmp",
+               "yz background",
+    "Toggle yz background image",
+               DoBkgrndToggleYZ,
+               IToolbarButton::eToggleButton
+       },
+       {
+               "bkgrnd2d_conf.bmp",
+               "Configure",
+    "Configure background images",
+               ShowBackgroundDialog,
+               IToolbarButton::eButton
+       },
+};
+
+class Bkgrnd2dButton : public IToolbarButton
+{
+public:
+  const toolbar_button_info_s *bi;
+  virtual const char* getImage() const
+  {
+    return bi->image;
+  }
+  virtual const char* getText() const
+  {
+    return bi->text;
+  }
+  virtual const char* getTooltip() const
+  {
+    return bi->tip;
+  }
+  virtual void activate() const
+  {
+    bi->func();
+    return ;
+  }
+  virtual EType getType() const
+  {
+    return bi->type;
+  }
+};
+
+Bkgrnd2dButton g_bkgrnd2dbuttons[NUM_TOOLBAR_BUTTONS];
+
+unsigned int ToolbarButtonCount()
+{
+  return NUM_TOOLBAR_BUTTONS;
+}
+
+const IToolbarButton* GetToolbarButton(unsigned int index)
+{
+  g_bkgrnd2dbuttons[index].bi = &toolbar_buttons[index];
+  return &g_bkgrnd2dbuttons[index];
+}
+
+extern "C" const char* QERPlug_Init (void *hApp, void* pMainWidget)
+{
+  g_pMainWidget = pMainWidget;
+
+  InitBackgroundDialog();
+  render.Register();
+
+//TODO is it right ? is it wrong ? it works
+//TODO figure out supported image types
+  GetFileTypeRegistry()->addType(FILETYPE_KEY, filetype_t("all files", "*.*"));
+  GetFileTypeRegistry()->addType(FILETYPE_KEY, filetype_t("jpeg files", "*.jpg"));
+  GetFileTypeRegistry()->addType(FILETYPE_KEY, filetype_t("targa files", "*.tga"));
+  return (char *) PLUGIN_NAME;
+}
+
+extern "C" const char* QERPlug_GetName ()
+{
+  return (char *) PLUGIN_NAME;
+}
+
+extern "C" const char* QERPlug_GetCommandList ()
+{
+  return (char *) PLUGIN_COMMANDS;
+}
+
+extern "C" void QERPlug_Dispatch (const char *p, vec3_t vMin, vec3_t vMax, bool bSingleBrush)
+{
+  Sys_Printf (MSG_PREFIX "Command \"%s\"\n",p); 
+  if(!strcmp(p, CMD_ABOUT)) {
+       g_FuncTable.m_pfnMessageBox(NULL, PLUGIN_ABOUT, "About", MB_OK, NULL);
+  } 
+  else if(!strcmp(p,CMD_CONFIG)) {
+       ShowBackgroundDialog();
+  }
+}
+
+//TODO these three suck
+void DoBkgrndToggleXY()
+{
+  Sys_Printf (MSG_PREFIX "DoBkgrndToggleXY\n"); 
+  // always toggle, since the buttons do
+  backgroundXY.m_bActive = (backgroundXY.m_bActive) ? false:true;
+  // if we don't have image or extents, and we activated,
+  // bring up the dialog with the corresponding page
+  // would be better to hide or grey out button, but we can't
+  if(backgroundXY.m_bActive && !backgroundXY.Valid())
+         ShowBackgroundDialogPG(0);
+  else
+         g_FuncTable.m_pfnSysUpdateWindows(W_XY);
+}
+
+void DoBkgrndToggleXZ()
+{
+  Sys_Printf (MSG_PREFIX "DoBkgrndToggleXZ\n"); 
+  backgroundXZ.m_bActive = (backgroundXZ.m_bActive) ? false:true;
+  if(backgroundXZ.m_bActive && !backgroundXZ.Valid())
+         ShowBackgroundDialogPG(1);
+  else
+         g_FuncTable.m_pfnSysUpdateWindows(W_XY);
+}
+
+void DoBkgrndToggleYZ()
+{
+  Sys_Printf (MSG_PREFIX "DoBkgrndToggleYZ\n"); 
+  backgroundYZ.m_bActive = (backgroundYZ.m_bActive) ? false:true;
+  if(backgroundYZ.m_bActive && !backgroundYZ.Valid())
+         ShowBackgroundDialogPG(2);
+  else
+         g_FuncTable.m_pfnSysUpdateWindows(W_XY);
+}
+
+// =============================================================================
+// SYNAPSE
+
+CSynapseServer* g_pSynapseServer = NULL;
+CSynapseClientBkgrnd2d g_SynapseClient;
+    
+extern "C" CSynapseClient* SYNAPSE_DLL_EXPORT Synapse_EnumerateInterfaces (const char *version, CSynapseServer *pServer)
+{
+  if (strcmp(version, SYNAPSE_VERSION))
+  {
+    Syn_Printf("ERROR: synapse API version mismatch: should be '" SYNAPSE_VERSION "', got '%s'\n", version);
+    return NULL;
+  }
+  g_pSynapseServer = pServer;
+  g_pSynapseServer->IncRef();
+  Set_Syn_Printf(g_pSynapseServer->Get_Syn_Printf());
+
+  g_SynapseClient.AddAPI(TOOLBAR_MAJOR, BKGRND2D_MINOR, sizeof(_QERPlugToolbarTable));
+  g_SynapseClient.AddAPI(PLUGIN_MAJOR, BKGRND2D_MINOR, sizeof( _QERPluginTable ) );
+
+  g_SynapseClient.AddAPI( RADIANT_MAJOR, NULL, sizeof( g_FuncTable ), SYN_REQUIRE, &g_FuncTable );
+  g_SynapseClient.AddAPI( QGL_MAJOR, NULL, sizeof( g_QglTable ), SYN_REQUIRE, &g_QglTable );
+// TODO is this the right way to ask for 'whichever VFS we have loaded' ? Seems to work
+// for misc filename functions
+  g_SynapseClient.AddAPI( VFS_MAJOR, "*", sizeof( g_FileSystemTable ), SYN_REQUIRE, &g_FileSystemTable );
+// get worldspawn
+  g_SynapseClient.AddAPI( ENTITY_MAJOR, NULL, sizeof( g_EntityTable ), SYN_REQUIRE, &g_EntityTable );
+// selected brushes
+  g_SynapseClient.AddAPI( DATA_MAJOR, NULL, sizeof( g_DataTable ), SYN_REQUIRE, &g_DataTable );
+
+  return &g_SynapseClient;
+}
+
+bool CSynapseClientBkgrnd2d::RequestAPI(APIDescriptor_t *pAPI)
+{
+  if (!strcmp(pAPI->major_name, PLUGIN_MAJOR))
+  {
+    _QERPluginTable* pTable= static_cast<_QERPluginTable*>(pAPI->mpTable);
+
+    pTable->m_pfnQERPlug_Init = QERPlug_Init;
+    pTable->m_pfnQERPlug_GetName = QERPlug_GetName;
+    pTable->m_pfnQERPlug_GetCommandList = QERPlug_GetCommandList;
+    pTable->m_pfnQERPlug_Dispatch = QERPlug_Dispatch;
+    return true;
+  }
+  if (!strcmp(pAPI->major_name, TOOLBAR_MAJOR))
+  {
+    _QERPlugToolbarTable* pTable= static_cast<_QERPlugToolbarTable*>(pAPI->mpTable);
+
+    pTable->m_pfnToolbarButtonCount = &ToolbarButtonCount;
+    pTable->m_pfnGetToolbarButton = &GetToolbarButton;
+    return true;
+  }
+
+  Syn_Printf("ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo());
+  return false;
+}
+
+#include "version.h"
+
+const char* CSynapseClientBkgrnd2d::GetInfo()
+{
+  return "2d Background plugin built " __DATE__ " " RADIANT_VERSION;
+}
+
+const char* CSynapseClientBkgrnd2d::GetName()
+{
+  return "bkgrnd2d";
+}
+