]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - contrib/bobtoolz/bobToolz-GTK.cpp
* applied patch by StefanV (from mailinglist) that fixes an error in config.py (broke...
[xonotic/netradiant.git] / contrib / bobtoolz / bobToolz-GTK.cpp
index be4f7804c67f41e929d5a7b6c54c06d305589983..d824df5402b7d040dcb33a64d15ac7d681001309 100644 (file)
@@ -17,52 +17,29 @@ License along with this library; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
-
-
-#include "str.h"
-#include "qerplugin.h"
-#include "mathlib.h"
-#include "string/string.h"
-#include "itoolbar.h"
+#include "StdAfx.h"
 
 #include "funchandlers.h"
-#include "DBobView.h"
-#include "DVisDrawer.h"
-#include "DTrainDrawer.h"
-#include "DTreePlanter.h"
+#include "misc.h"
 
 #include "dialogs/dialogs-gtk.h"
 #include "../../libs/cmdlib.h"
 
-void BobToolz_construct()
-{
-}
-
-void BobToolz_destroy()
-{
-       if(g_PathView) {
-               delete g_PathView;
-               g_PathView = NULL;
-       }
-       if(g_VisView) {
-               delete g_VisView;
-               g_VisView = NULL;
-       }
-       if(g_TrainView) {
-               delete g_TrainView;
-               g_TrainView = NULL;
-       }
-       if(g_TreePlanter) {
-               delete g_TreePlanter;
-               g_TreePlanter = NULL;
-       }
-}
+// Radiant function table
+_QERFuncTable_1                          g_FuncTable;
+_QERAppDataTable                 g_AppDataTable;
+_QERBrushTable                   g_BrushTable;
+_QERShadersTable                 g_ShadersTable;                       // vvvvvvvvvvvvvvvvvvvv
+_QERSelectedFaceTable g_SelectedFaceTable;     // to get texture sizes
+_QERQglTable                             g_QglTable;                           // for path plotting (hooking to DBobView)
+_QERUITable                                      g_MessageTable;                       // for path plotting (listening for update)
+_QEREntityTable                          g_EntityTable;
 
 // plugin name
-char* PLUGIN_NAME = "bobToolz";
+const char* PLUGIN_NAME = "bobToolz";
 
 // commands in the menu
-static char* PLUGIN_COMMANDS = "About...,-,Reset Textures...,PitOMatic,-,Vis Viewer,Brush Cleanup,Polygon Builder,Caulk Selection,-,Tree Planter,Drop Entity,Plot Splines,-,Merge Patches,Split patches,Turn edge";
+static const char* PLUGIN_COMMANDS = "About...,-,Reset Textures...,PitOMatic,-,Vis Viewer,Brush Cleanup,Polygon Builder,Caulk Selection,-,Tree Planter,Drop Entity,Plot Splines,-,Merge Patches,Split patches,Turn edge";
 
 // globals
 GtkWidget *g_pRadiantWnd = NULL;
@@ -90,45 +67,54 @@ extern "C" const char* QERPlug_GetCommandList() {
 extern "C" void QERPlug_Dispatch (const char *p, vec3_t vMin, vec3_t vMax, bool bSingleBrush) {
        LoadLists();
 
-       if( string_equal_nocase( p, "brush cleanup" ) ) {
+       if( !stricmp( p, "brush cleanup" ) ) {
     DoFixBrushes();
-  } else if( string_equal_nocase( p, "polygon builder" ) ) {
+  } else if( !stricmp( p, "polygon builder" ) ) {
     DoPolygonsTB();
-  } else if( string_equal_nocase( p, "caulk selection" ) ) {
+  } else if( !stricmp( p, "caulk selection" ) ) {
     DoCaulkSelection();
-  } else if( string_equal_nocase( p, "tree planter" ) ) {
+  } else if( !stricmp( p, "tree planter" ) ) {
     DoTreePlanter();
-  } else if( string_equal_nocase( p, "plot splines" ) ) {
+  } else if( !stricmp( p, "plot splines" ) ) {
     DoTrainPathPlot();
-  } else if( string_equal_nocase( p, "drop entity" ) ) {
+  } else if( !stricmp( p, "drop entity" ) ) {
     DoDropEnts();
-  } else if( string_equal_nocase( p, "merge patches" ) ) {
+  } else if( !stricmp( p, "merge patches" ) ) {
     DoMergePatches();
-  } else if( string_equal_nocase( p, "split patches" ) ) {
+  } else if( !stricmp( p, "split patches" ) ) {
     DoSplitPatch();
-  } else if( string_equal_nocase( p, "turn edge" ) ) {
+  } else if( !stricmp( p, "turn edge" ) ) {
     DoFlipTerrain();
-  } else if( string_equal_nocase(p, "reset textures...") ) {
+  } else if( !stricmp(p, "reset textures...") ) {
                DoResetTextures();
-       } else if( string_equal_nocase(p, "pitomatic") ) {
-               DoPitBuilder();
-       } else if( string_equal_nocase(p, "vis viewer") ) {
+       } else if( !stricmp(p, "pitomatic") ) {
+               DoPitBuilder(vMin, vMax);
+       } else if( !stricmp(p, "vis viewer") ) {
                DoVisAnalyse();
-       } else if( string_equal_nocase(p, "about...") ) {
-               DoMessageBox(PLUGIN_ABOUT, "About", eMB_OK);
+       } else if( !stricmp(p, "about...") ) {
+               DoMessageBox(PLUGIN_ABOUT, "About", IDOK);
        }
 }
 
-const char* QERPlug_GetCommandTitleList()
-{
-  return "";
+#define NUM_TOOLBARBUTTONS 9
+
+unsigned int ToolbarButtonCount( void ) {
+       return NUM_TOOLBARBUTTONS;
 }
 
+// Load a xpm file and return a pixmap widget.
+GtkWidget* new_pixmap (char* filename) {
+       GdkPixmap *gdkpixmap;
+       GdkBitmap *mask;
+       GtkWidget *pixmap;
 
-#define NUM_TOOLBARBUTTONS 9
+       g_FuncTable.m_pfnLoadBitmap(filename, (void **)&gdkpixmap, (void **)&mask);
+       pixmap = gtk_pixmap_new (gdkpixmap, mask);
 
-std::size_t ToolbarButtonCount( void ) {
-       return NUM_TOOLBARBUTTONS;
+       gdk_pixmap_unref (gdkpixmap);
+       gdk_pixmap_unref (mask);
+
+       return pixmap;
 }
 
 class CBobtoolzToolbarButton : public IToolbarButton
@@ -154,7 +140,7 @@ public:
     switch( mIndex ) {
       case 3: return eToggleButton;
       default: return eButton;
-    }    
+    }
   }
   virtual const char* getText() const
   {
@@ -204,125 +190,108 @@ public:
     }
   }
 
-  std::size_t mIndex;
+  int mIndex;
 };
 
 CBobtoolzToolbarButton g_bobtoolzToolbarButtons[NUM_TOOLBARBUTTONS];
 
-const IToolbarButton* GetToolbarButton(std::size_t index)
+const IToolbarButton* GetToolbarButton(unsigned int index)
 {
   g_bobtoolzToolbarButtons[index].mIndex = index;
   return &g_bobtoolzToolbarButtons[index];
 }
 
+// =============================================================================
+// SYNAPSE
 
-#include "modulesystem/singletonmodule.h"
-
-#include "iscenegraph.h"
-#include "irender.h"
-#include "iundo.h"
-#include "ishaders.h"
-#include "ipatch.h"
-#include "ibrush.h"
-#include "ientity.h"
-#include "ieclass.h"
-#include "iglrender.h"
-#include "iplugin.h"
-
-class BobToolzPluginDependencies :
-  public GlobalRadiantModuleRef,
-  public GlobalUndoModuleRef,
-  public GlobalSceneGraphModuleRef,
-  public GlobalSelectionModuleRef,
-  public GlobalEntityModuleRef,
-  public GlobalEntityClassManagerModuleRef,
-  public GlobalShadersModuleRef,
-  public GlobalShaderCacheModuleRef,
-  public GlobalBrushModuleRef,
-  public GlobalPatchModuleRef,
-  public GlobalOpenGLModuleRef, 
-  public GlobalOpenGLStateLibraryModuleRef
+class CSynapseClientBobtoolz : public CSynapseClient
 {
 public:
-  BobToolzPluginDependencies() :
-    GlobalEntityModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("entities")),
-    GlobalShadersModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("shaders")),
-    GlobalBrushModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("brushtypes")),
-    GlobalPatchModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("patchtypes")),
-    GlobalEntityClassManagerModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("entityclass"))
-  {
-  }
+  // CSynapseClient API
+  bool RequestAPI(APIDescriptor_t *pAPI);
+  const char* GetInfo();
+
+  CSynapseClientBobtoolz() { }
+  virtual ~CSynapseClientBobtoolz() { }
 };
 
-class BobToolzPluginModule : public TypeSystemRef
-{
-  _QERPluginTable m_plugin;
-public:
-  typedef _QERPluginTable Type;
-  STRING_CONSTANT(Name, "bobtoolz");
 
-  BobToolzPluginModule()
-  {
-    m_plugin.m_pfnQERPlug_Init = QERPlug_Init;
-    m_plugin.m_pfnQERPlug_GetName = QERPlug_GetName;
-    m_plugin.m_pfnQERPlug_GetCommandList = QERPlug_GetCommandList;
-    m_plugin.m_pfnQERPlug_GetCommandTitleList = QERPlug_GetCommandTitleList;
-    m_plugin.m_pfnQERPlug_Dispatch = QERPlug_Dispatch;
+CSynapseServer* g_pSynapseServer = NULL;
+CSynapseClientBobtoolz g_SynapseClient;
 
-    BobToolz_construct();
-  }
-  ~BobToolzPluginModule()
-  {
-    BobToolz_destroy();
-  }
-  _QERPluginTable* getTable()
+#if __GNUC__ >= 4
+#pragma GCC visibility push(default)
+#endif
+extern "C" CSynapseClient* SYNAPSE_DLL_EXPORT Synapse_EnumerateInterfaces( const char *version, CSynapseServer *pServer ) {
+#if __GNUC__ >= 4
+#pragma GCC visibility pop
+#endif
+  if (strcmp(version, SYNAPSE_VERSION))
   {
-    return &m_plugin;
+    Syn_Printf("ERROR: synapse API version mismatch: should be '" SYNAPSE_VERSION "', got '%s'\n", version);
+    return NULL;
   }
-};
-
-typedef SingletonModule<BobToolzPluginModule, BobToolzPluginDependencies> SingletonBobToolzPluginModule;
-
-SingletonBobToolzPluginModule g_BobToolzPluginModule;
-
+  g_pSynapseServer = pServer;
+  g_pSynapseServer->IncRef();
+  Set_Syn_Printf(g_pSynapseServer->Get_Syn_Printf());
+
+  g_SynapseClient.AddAPI(TOOLBAR_MAJOR, BOBTOOLZ_MINOR, sizeof(_QERPlugToolbarTable));
+  g_SynapseClient.AddAPI(PLUGIN_MAJOR, BOBTOOLZ_MINOR, sizeof(_QERPluginTable));
+
+  g_SynapseClient.AddAPI(DATA_MAJOR, NULL, sizeof(g_AppDataTable), SYN_REQUIRE, &g_AppDataTable);
+  g_SynapseClient.AddAPI(BRUSH_MAJOR, NULL, sizeof(g_BrushTable), SYN_REQUIRE, &g_BrushTable);
+  g_SynapseClient.AddAPI(SHADERS_MAJOR, "*", sizeof(g_ShadersTable), SYN_REQUIRE, &g_ShadersTable);
+  g_SynapseClient.AddAPI(ENTITY_MAJOR, NULL, sizeof(g_EntityTable), SYN_REQUIRE, &g_EntityTable);
+  g_SynapseClient.AddAPI(SELECTEDFACE_MAJOR, NULL, sizeof(g_SelectedFaceTable), SYN_REQUIRE, &g_SelectedFaceTable);
+  g_SynapseClient.AddAPI(UI_MAJOR, NULL, sizeof(g_MessageTable), SYN_REQUIRE, &g_MessageTable);
+  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);
+
+  return &g_SynapseClient;
+}
 
-class BobToolzToolbarDependencies :
-  public ModuleRef<_QERPluginTable>
+bool CSynapseClientBobtoolz::RequestAPI(APIDescriptor_t *pAPI)
 {
-public:
-  BobToolzToolbarDependencies() :
-    ModuleRef<_QERPluginTable>("bobtoolz")
+  if( !strcmp(pAPI->minor_name, BOBTOOLZ_MINOR) )
   {
-  }
-};
+    if( !strcmp(pAPI->major_name, PLUGIN_MAJOR) )
+    {
+      _QERPluginTable* pTable= static_cast<_QERPluginTable*>(pAPI->mpTable);
 
-class BobToolzToolbarModule : public TypeSystemRef
-{
-  _QERPlugToolbarTable m_table;
-public:
-  typedef _QERPlugToolbarTable Type;
-  STRING_CONSTANT(Name, "bobtoolz");
+      pTable->m_pfnQERPlug_Init = QERPlug_Init;
+      pTable->m_pfnQERPlug_GetName = QERPlug_GetName;
+      pTable->m_pfnQERPlug_GetCommandList = QERPlug_GetCommandList;
+      pTable->m_pfnQERPlug_Dispatch = QERPlug_Dispatch;
 
-  BobToolzToolbarModule()
-  {
-    m_table.m_pfnToolbarButtonCount = ToolbarButtonCount;
-    m_table.m_pfnGetToolbarButton = GetToolbarButton;
-  }
-  _QERPlugToolbarTable* getTable()
-  {
-    return &m_table;
-  }
-};
+      return true;
+    }
+    else if( !strcmp(pAPI->major_name, TOOLBAR_MAJOR) )
+    {
+      _QERPlugToolbarTable* pTable= static_cast<_QERPlugToolbarTable*>(pAPI->mpTable);
+
+      pTable->m_pfnToolbarButtonCount = &ToolbarButtonCount;
+      pTable->m_pfnGetToolbarButton = &GetToolbarButton;
 
-typedef SingletonModule<BobToolzToolbarModule, BobToolzToolbarDependencies> SingletonBobToolzToolbarModule;
+      return true;
+    }
+  }
 
-SingletonBobToolzToolbarModule g_BobToolzToolbarModule;
+  Syn_Printf("ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo());
+  return false;
+}
 
+#include "version.h"
 
-extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules(ModuleServer& server)
+const char* CSynapseClientBobtoolz::GetInfo()
 {
-  initialiseModule(server);
+  return "bobToolz module built " __DATE__ " " RADIANT_VERSION;
+}
 
-  g_BobToolzPluginModule.selfRegister();
-  g_BobToolzToolbarModule.selfRegister();
+char* GetFilename(char* buffer, const char* filename) {
+       strcpy(buffer, g_pSynapseServer->GetModuleFilename(&g_SynapseClient));
+       StripFilename( buffer );
+       strcat(buffer, "/");
+       strcat(buffer, filename);
+       buffer = UnixToDosPath(buffer);
+       return buffer;
 }