]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - contrib/bobtoolz/bobToolz-GTK.cpp
integrated bobtoolz patch from LordHavoc
[xonotic/netradiant.git] / contrib / bobtoolz / bobToolz-GTK.cpp
index 08cd00dd0855501d048d0e832250b528be409e6b..26578e93802b08b4a0d1308fcf253ce378c5f898 100644 (file)
@@ -17,27 +17,46 @@ 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 "libxml/parser.h"
 
-#include "StdAfx.h"
 
 #include "str.h"
-//#include "gtkr_list.h"
+#include "qerplugin.h"
+#include "mathlib.h"
+#include "string/string.h"
+#include "itoolbar.h"
 
 #include "funchandlers.h"
-//#include "misc.h"
+#include "DBobView.h"
+#include "DVisDrawer.h"
+#include "DTrainDrawer.h"
+#include "DTreePlanter.h"
 
 #include "dialogs/dialogs-gtk.h"
 #include "../../libs/cmdlib.h"
 
-// Radiant function table
-_QERFuncTable_1                          __QERTABLENAME;
-_QERShadersTable                 __SHADERSTABLENAME;                   // vvvvvvvvvvvvvvvvvvvv
-_QERQglTable                             __QGLTABLENAME;                               // for path plotting (hooking to DBobView)
-_QERUITable                                      g_MessageTable;                       // for path plotting (listening for update)
-_QEREntityTable                          __ENTITYTABLENAME;
-_QERBrushTable                   __BRUSHTABLENAME;
-_QERPatchTable                   __PATCHTABLENAME;
+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;
+       }
+}
 
 // plugin name
 char* PLUGIN_NAME = "bobToolz";
@@ -71,55 +90,46 @@ extern "C" const char* QERPlug_GetCommandList() {
 extern "C" void QERPlug_Dispatch (const char *p, vec3_t vMin, vec3_t vMax, bool bSingleBrush) {
        LoadLists();
 
-       if( !stricmp( p, "brush cleanup" ) ) {
+       if( string_equal_nocase( p, "brush cleanup" ) ) {
     DoFixBrushes();
-  } else if( !stricmp( p, "polygon builder" ) ) {
+  } else if( string_equal_nocase( p, "polygon builder" ) ) {
     DoPolygonsTB();
-  } else if( !stricmp( p, "caulk selection" ) ) {
+  } else if( string_equal_nocase( p, "caulk selection" ) ) {
     DoCaulkSelection();
-  } else if( !stricmp( p, "tree planter" ) ) {
+  } else if( string_equal_nocase( p, "tree planter" ) ) {
     DoTreePlanter();
-  } else if( !stricmp( p, "plot splines" ) ) {
+  } else if( string_equal_nocase( p, "plot splines" ) ) {
     DoTrainPathPlot();
-  } else if( !stricmp( p, "drop entity" ) ) {
+  } else if( string_equal_nocase( p, "drop entity" ) ) {
     DoDropEnts();
-  } else if( !stricmp( p, "merge patches" ) ) {
+  } else if( string_equal_nocase( p, "merge patches" ) ) {
     DoMergePatches();
-  } else if( !stricmp( p, "split patches" ) ) {
+  } else if( string_equal_nocase( p, "split patches" ) ) {
     DoSplitPatch();
-  } else if( !stricmp( p, "turn edge" ) ) {
+  } else if( string_equal_nocase( p, "turn edge" ) ) {
     DoFlipTerrain();
-  } else if( !stricmp(p, "reset textures...") ) {
+  } else if( string_equal_nocase(p, "reset textures...") ) {
                DoResetTextures();
-       } else if( !stricmp(p, "pitomatic") ) {
+       } else if( string_equal_nocase(p, "pitomatic") ) {
                DoPitBuilder();
-       } else if( !stricmp(p, "vis viewer") ) {
+       } else if( string_equal_nocase(p, "vis viewer") ) {
                DoVisAnalyse();
-       } else if( !stricmp(p, "about...") ) {
+       } else if( string_equal_nocase(p, "about...") ) {
                DoMessageBox(PLUGIN_ABOUT, "About", eMB_OK);
        }
 }
 
-#define NUM_TOOLBARBUTTONS 9
-
-unsigned int ToolbarButtonCount( void ) {
-       return NUM_TOOLBARBUTTONS;
+const char* QERPlug_GetCommandTitleList()
+{
+  return "";
 }
 
-// Load a xpm file and return a pixmap widget.
-GtkWidget* new_pixmap (char* filename) {
-       GdkPixmap *gdkpixmap;
-       GdkBitmap *mask;
-       GtkWidget *pixmap;
 
-       g_FuncTable.m_pfnLoadBitmap(filename, (void **)&gdkpixmap, (void **)&mask);     
-       pixmap = gtk_pixmap_new (gdkpixmap, mask);
-
-       gdk_pixmap_unref (gdkpixmap);
-       gdk_pixmap_unref (mask);
+#define NUM_TOOLBARBUTTONS 9
 
-       return pixmap;
-} 
+std::size_t ToolbarButtonCount( void ) {
+       return NUM_TOOLBARBUTTONS;
+}
 
 class CBobtoolzToolbarButton : public IToolbarButton
 {
@@ -199,100 +209,120 @@ public:
 
 CBobtoolzToolbarButton g_bobtoolzToolbarButtons[NUM_TOOLBARBUTTONS];
 
-const IToolbarButton* GetToolbarButton(unsigned int index)
+const IToolbarButton* GetToolbarButton(std::size_t index)
 {
   g_bobtoolzToolbarButtons[index].mIndex = index;
   return &g_bobtoolzToolbarButtons[index];
 }
 
-// =============================================================================
-// SYNAPSE
-
-#include "synapse.h"
 
-class CSynapseClientBobtoolz : public CSynapseClient
+#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
 {
 public:
-  // CSynapseClient API
-  bool RequestAPI(APIDescriptor_t *pAPI);
-  const char* GetInfo();
-  
-  CSynapseClientBobtoolz() { }
-  virtual ~CSynapseClientBobtoolz() { }
+  BobToolzPluginDependencies() :
+    GlobalEntityModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("entities")),
+    GlobalShadersModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("shaders")),
+    GlobalBrushModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("brushtypes")),
+    GlobalPatchModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("patchtypes")),
+    GlobalEntityClassManagerModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("entityclass"))
+  {
+  }
 };
 
+class BobToolzPluginModule : public TypeSystemRef
+{
+  _QERPluginTable m_plugin;
+public:
+  typedef _QERPluginTable Type;
+  STRING_CONSTANT(Name, "bobtoolz");
 
-CSynapseServer* g_pSynapseServer = NULL;
-CSynapseClientBobtoolz g_SynapseClient;
+  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;
 
-extern "C" CSynapseClient* SYNAPSE_DLL_EXPORT Synapse_EnumerateInterfaces (const char *version, CSynapseServer *pServer)
-{
-  if (strcmp(version, SYNAPSE_VERSION))
+    BobToolz_construct();
+  }
+  ~BobToolzPluginModule()
   {
-    Syn_Printf("ERROR: synapse API version mismatch: should be '" SYNAPSE_VERSION "', got '%s'\n", version);
-    return NULL;
+    BobToolz_destroy();
   }
-  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(BRUSH_MAJOR, NULL, sizeof(__BRUSHTABLENAME), SYN_REQUIRE, &g_BrushTable);
-  g_SynapseClient.AddAPI(PATCH_MAJOR, NULL, sizeof(__PATCHTABLENAME), 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(__QERTABLENAME), SYN_REQUIRE, &g_FuncTable);
-  g_SynapseClient.AddAPI(QGL_MAJOR, NULL, sizeof(g_QglTable), SYN_REQUIRE, &g_QglTable);
-
-  return &g_SynapseClient;
-}
-
-bool CSynapseClientBobtoolz::RequestAPI(APIDescriptor_t *pAPI)
-{
-  if( !strcmp(pAPI->minor_name, BOBTOOLZ_MINOR) )
+  _QERPluginTable* getTable()
   {
-    if( !strcmp(pAPI->major_name, PLUGIN_MAJOR) )
-    {
-      _QERPluginTable* pTable= static_cast<_QERPluginTable*>(pAPI->mpTable);
+    return &m_plugin;
+  }
+};
 
-      pTable->m_pfnQERPlug_Init = QERPlug_Init;
-      pTable->m_pfnQERPlug_GetName = QERPlug_GetName;
-      pTable->m_pfnQERPlug_GetCommandList = QERPlug_GetCommandList;
-      pTable->m_pfnQERPlug_Dispatch = QERPlug_Dispatch;
+typedef SingletonModule<BobToolzPluginModule, BobToolzPluginDependencies> SingletonBobToolzPluginModule;
 
-      return true;
-    }
-    else if( !strcmp(pAPI->major_name, TOOLBAR_MAJOR) )
-    {
-      _QERPlugToolbarTable* pTable= static_cast<_QERPlugToolbarTable*>(pAPI->mpTable);
+SingletonBobToolzPluginModule g_BobToolzPluginModule;
 
-      pTable->m_pfnToolbarButtonCount = &ToolbarButtonCount;
-      pTable->m_pfnGetToolbarButton = &GetToolbarButton;
 
-      return true;
-    }
+class BobToolzToolbarDependencies :
+  public ModuleRef<_QERPluginTable>
+{
+public:
+  BobToolzToolbarDependencies() :
+    ModuleRef<_QERPluginTable>("bobtoolz")
+  {
+  }
+};
+
+class BobToolzToolbarModule : public TypeSystemRef
+{
+  _QERPlugToolbarTable m_table;
+public:
+  typedef _QERPlugToolbarTable Type;
+  STRING_CONSTANT(Name, "bobtoolz");
+
+  BobToolzToolbarModule()
+  {
+    m_table.m_pfnToolbarButtonCount = ToolbarButtonCount;
+    m_table.m_pfnGetToolbarButton = GetToolbarButton;
   }
+  _QERPlugToolbarTable* getTable()
+  {
+    return &m_table;
+  }
+};
 
-  Syn_Printf("ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo());
-  return false;
-}
+typedef SingletonModule<BobToolzToolbarModule, BobToolzToolbarDependencies> SingletonBobToolzToolbarModule;
+
+SingletonBobToolzToolbarModule g_BobToolzToolbarModule;
 
-#include "version.h"
 
-const char* CSynapseClientBobtoolz::GetInfo()
+extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules(ModuleServer& server)
 {
-  return "bobToolz module built " __DATE__ " " RADIANT_VERSION;
-}
+  initialiseModule(server);
 
-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;
+  g_BobToolzPluginModule.selfRegister();
+  g_BobToolzToolbarModule.selfRegister();
 }