]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - contrib/shaderplug/shaderplug.cpp
fix lots of CRLFs
[xonotic/netradiant.git] / contrib / shaderplug / shaderplug.cpp
index facb38224cf582f70a3b20565793a8f055636316..6554790bac741e51431f19a11f170eeab062a66c 100644 (file)
-/*\r
-Copyright (C) 2006, Stefan Greven.\r
-All Rights Reserved.\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
-#include "shaderplug.h"\r
-\r
-#include "debugging/debugging.h"\r
-\r
-#include <string>\r
-#include <vector>\r
-#include "string/string.h"\r
-#include "modulesystem/singletonmodule.h"\r
-#include "stream/stringstream.h"\r
-#include "os/file.h"\r
-\r
-#include <gtk/gtk.h>\r
-\r
-#include "iplugin.h"\r
-#include "qerplugin.h"\r
-#include "ifilesystem.h"\r
-#include "iarchive.h"\r
-#include "ishaders.h"\r
-#include "iscriplib.h"\r
-\r
-#include "generic/callback.h"\r
-\r
-namespace {\r
-const char SHADERTAG_FILE[] = "shadertags.xml";\r
-}\r
-\r
-class ShaderPlugPluginDependencies : public GlobalRadiantModuleRef,\r
-                                     public GlobalFileSystemModuleRef,\r
-                                     public GlobalShadersModuleRef\r
-{\r
-public:\r
-  ShaderPlugPluginDependencies() :\r
-      GlobalShadersModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("shaders"))\r
-  {\r
-  }\r
-};\r
-\r
-namespace Shaderplug\r
-{\r
-  GtkWindow* g_window;\r
-\r
-  std::vector<const char*> archives;\r
-  std::set<std::string> shaders;\r
-  std::set<std::string> textures;\r
-\r
-  XmlTagBuilder TagBuilder;\r
-  void CreateTagFile();\r
-\r
-  const char* init(void* hApp, void* pMainWidget)\r
-  {\r
-    g_window = GTK_WINDOW(pMainWidget);\r
-    return "";\r
-  }\r
-  const char* getName()\r
-  {\r
-    return "ShaderPlug";\r
-  }\r
-  const char* getCommandList()\r
-  {\r
-    return "About;Create tag file";\r
-  }\r
-  const char* getCommandTitleList()\r
-  {\r
-    return "";\r
-  }\r
-  void dispatch(const char* command, float* vMin, float* vMax, bool bSingleBrush)\r
-  {\r
-    if(string_equal(command, "About"))\r
-    {\r
-      GlobalRadiant().m_pfnMessageBox(GTK_WIDGET(g_window), "Shaderplug (1.0)\n\n"\r
-                                        "by Shaderman (shaderman@gmx.net)",\r
-                                        "About",\r
-                                        eMB_OK,\r
-                                        eMB_ICONDEFAULT);\r
-    }\r
-    if(string_equal(command, "Create tag file"))\r
-    {\r
-      CreateTagFile();\r
-    }\r
-  }\r
-\r
-  void loadArchiveFile(const char* filename)\r
-  {\r
-    archives.push_back(filename);\r
-  }\r
-\r
-  typedef FreeCaller1<const char*, loadArchiveFile> LoadArchiveFileCaller;\r
-\r
-  void LoadTextureFile(const char* filename)\r
-  {\r
-    std::string s_filename = filename;\r
-\r
-    char buffer[256];\r
-    strcpy(buffer, "textures/");\r
-\r
-    // append filename without trailing file extension (.tga or .jpg for example)\r
-    strncat(buffer, filename, s_filename.length() - 4);\r
-\r
-    std::set<std::string>::iterator iter;\r
-    iter = shaders.find(buffer);\r
-\r
-    // a shader with this name already exists\r
-    if(iter == shaders.end())\r
-    {\r
-      textures.insert(buffer);\r
-    }\r
-  }\r
-\r
-  typedef FreeCaller1<const char*, LoadTextureFile> LoadTextureFileCaller;\r
-\r
-  void GetTextures(char* extension)\r
-  {\r
-    GlobalFileSystem().forEachFile("textures/", extension, LoadTextureFileCaller(), 0);\r
-  }\r
-\r
-  void LoadShaderList(const char* filename)\r
-  {\r
-    if(string_equal_prefix(filename, "textures/"))\r
-    {\r
-      shaders.insert(filename);\r
-    }\r
-  }\r
-\r
-  typedef FreeCaller1<const char*, LoadShaderList> LoadShaderListCaller;\r
-\r
-  void GetAllShaders()\r
-  {\r
-    GlobalShaderSystem().foreachShaderName(LoadShaderListCaller());\r
-  }\r
-\r
-  void GetArchiveList()\r
-  {\r
-    GlobalFileSystem().forEachArchive(LoadArchiveFileCaller());\r
-    globalOutputStream() << "Shaderplug: " << (const Unsigned)Shaderplug::archives.size() << " archives found.\n";\r
-  }\r
-\r
-  void CreateTagFile()\r
-  {\r
-    const char* shader_type = GlobalRadiant().getGameDescriptionKeyValue("shaders");\r
-\r
-    GetAllShaders();\r
-    globalOutputStream() << "Shaderplug: " << (const Unsigned)shaders.size() << " shaders found.\n";\r
-\r
-    if(string_equal(shader_type, "quake3"))\r
-    {\r
-      GetTextures("jpg");\r
-      GetTextures("tga");\r
-      GetTextures("png");\r
-\r
-      globalOutputStream() << "Shaderplug: " << (const Unsigned)textures.size() << " textures found.\n";\r
-    }\r
-\r
-    if(shaders.size() || textures.size() != 0)\r
-    {\r
-      globalOutputStream() << "Shaderplug: Creating XML tag file.\n";\r
-\r
-      TagBuilder.CreateXmlDocument();\r
-\r
-      std::set<std::string>::reverse_iterator r_iter;\r
-\r
-      for(r_iter = textures.rbegin(); r_iter != textures.rend(); ++r_iter)\r
-      {\r
-        TagBuilder.AddShaderNode(const_cast<char*>((*r_iter).c_str()), STOCK, TEXTURE);\r
-      }\r
-\r
-      for(r_iter = shaders.rbegin(); r_iter != shaders.rend(); ++r_iter)\r
-      {\r
-        TagBuilder.AddShaderNode(const_cast<char*>((*r_iter).c_str()), STOCK, SHADER);\r
-      }\r
-\r
-      // Get the tag file        \r
-      StringOutputStream tagFileStream(256);\r
-         tagFileStream << GlobalRadiant().getLocalRcPath() << SHADERTAG_FILE;\r
-      char* tagFile = tagFileStream.c_str();\r
-\r
-      char message[256];\r
-      strcpy(message, "Tag file saved to\n");\r
-      strcat(message, tagFile);\r
-      strcat(message, "\nPlease restart Radiant now.\n");\r
-\r
-      if(file_exists(tagFile))\r
-      {\r
-        EMessageBoxReturn result = GlobalRadiant().m_pfnMessageBox(GTK_WIDGET(g_window),\r
-            "WARNING! A tag file already exists! Overwrite it?", "Overwrite tag file?",\r
-            eMB_NOYES,\r
-            eMB_ICONWARNING);\r
-\r
-        if(result == eIDYES)\r
-        {\r
-          TagBuilder.SaveXmlDoc(tagFile);\r
-          GlobalRadiant().m_pfnMessageBox(GTK_WIDGET(g_window), message, "INFO", eMB_OK, eMB_ICONASTERISK);\r
-        }\r
-      } else {\r
-        TagBuilder.SaveXmlDoc(tagFile);\r
-        GlobalRadiant().m_pfnMessageBox(GTK_WIDGET(g_window), message, "INFO", eMB_OK, eMB_ICONASTERISK);\r
-      }\r
-    } else {\r
-      GlobalRadiant().m_pfnMessageBox(GTK_WIDGET(g_window),\r
-          "No shaders or textures found. No XML tag file created!\n"\r
-          "",\r
-          "ERROR",\r
-          eMB_OK,\r
-          eMB_ICONERROR);\r
-    }\r
-  }\r
-} // namespace\r
-\r
-class ShaderPluginModule\r
-{\r
-  _QERPluginTable m_plugin;\r
-public:\r
-  typedef _QERPluginTable Type;\r
-  STRING_CONSTANT(Name, "ShaderPlug");\r
-\r
-  ShaderPluginModule()\r
-  {\r
-    m_plugin.m_pfnQERPlug_Init = &Shaderplug::init;\r
-    m_plugin.m_pfnQERPlug_GetName = &Shaderplug::getName;\r
-    m_plugin.m_pfnQERPlug_GetCommandList = &Shaderplug::getCommandList;\r
-    m_plugin.m_pfnQERPlug_GetCommandTitleList = &Shaderplug::getCommandTitleList;\r
-    m_plugin.m_pfnQERPlug_Dispatch = &Shaderplug::dispatch;\r
-  }\r
-  _QERPluginTable* getTable()\r
-  {\r
-    return &m_plugin;\r
-  }\r
-};\r
-\r
-typedef SingletonModule<ShaderPluginModule, ShaderPlugPluginDependencies> SingletonShaderPluginModule;\r
-\r
-SingletonShaderPluginModule g_ShaderPluginModule;\r
-\r
-extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules(ModuleServer& server)\r
-{\r
-  initialiseModule(server);\r
-\r
-  g_ShaderPluginModule.selfRegister();\r
-}\r
-\r
-\r
-\r
-\r
+/*
+Copyright (C) 2006, Stefan Greven.
+All Rights Reserved.
+
+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
+*/
+
+#include "shaderplug.h"
+
+#include "debugging/debugging.h"
+
+#include <string>
+#include <vector>
+#include "string/string.h"
+#include "modulesystem/singletonmodule.h"
+#include "stream/stringstream.h"
+#include "os/file.h"
+
+#include <gtk/gtk.h>
+
+#include "iplugin.h"
+#include "qerplugin.h"
+#include "ifilesystem.h"
+#include "iarchive.h"
+#include "ishaders.h"
+#include "iscriplib.h"
+
+#include "generic/callback.h"
+
+namespace {
+const char SHADERTAG_FILE[] = "shadertags.xml";
+}
+
+class ShaderPlugPluginDependencies : public GlobalRadiantModuleRef,
+                                     public GlobalFileSystemModuleRef,
+                                     public GlobalShadersModuleRef
+{
+public:
+  ShaderPlugPluginDependencies() :
+      GlobalShadersModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("shaders"))
+  {
+  }
+};
+
+namespace Shaderplug
+{
+  GtkWindow* g_window;
+
+  std::vector<const char*> archives;
+  std::set<std::string> shaders;
+  std::set<std::string> textures;
+
+  XmlTagBuilder TagBuilder;
+  void CreateTagFile();
+
+  const char* init(void* hApp, void* pMainWidget)
+  {
+    g_window = GTK_WINDOW(pMainWidget);
+    return "";
+  }
+  const char* getName()
+  {
+    return "ShaderPlug";
+  }
+  const char* getCommandList()
+  {
+    return "About;Create tag file";
+  }
+  const char* getCommandTitleList()
+  {
+    return "";
+  }
+  void dispatch(const char* command, float* vMin, float* vMax, bool bSingleBrush)
+  {
+    if(string_equal(command, "About"))
+    {
+      GlobalRadiant().m_pfnMessageBox(GTK_WIDGET(g_window), "Shaderplug (1.0)\n\n"
+                                        "by Shaderman (shaderman@gmx.net)",
+                                        "About",
+                                        eMB_OK,
+                                        eMB_ICONDEFAULT);
+    }
+    if(string_equal(command, "Create tag file"))
+    {
+      CreateTagFile();
+    }
+  }
+
+  void loadArchiveFile(const char* filename)
+  {
+    archives.push_back(filename);
+  }
+
+  typedef FreeCaller1<const char*, loadArchiveFile> LoadArchiveFileCaller;
+
+  void LoadTextureFile(const char* filename)
+  {
+    std::string s_filename = filename;
+
+    char buffer[256];
+    strcpy(buffer, "textures/");
+
+    // append filename without trailing file extension (.tga or .jpg for example)
+    strncat(buffer, filename, s_filename.length() - 4);
+
+    std::set<std::string>::iterator iter;
+    iter = shaders.find(buffer);
+
+    // a shader with this name already exists
+    if(iter == shaders.end())
+    {
+      textures.insert(buffer);
+    }
+  }
+
+  typedef FreeCaller1<const char*, LoadTextureFile> LoadTextureFileCaller;
+
+  void GetTextures(char* extension)
+  {
+    GlobalFileSystem().forEachFile("textures/", extension, LoadTextureFileCaller(), 0);
+  }
+
+  void LoadShaderList(const char* filename)
+  {
+    if(string_equal_prefix(filename, "textures/"))
+    {
+      shaders.insert(filename);
+    }
+  }
+
+  typedef FreeCaller1<const char*, LoadShaderList> LoadShaderListCaller;
+
+  void GetAllShaders()
+  {
+    GlobalShaderSystem().foreachShaderName(LoadShaderListCaller());
+  }
+
+  void GetArchiveList()
+  {
+    GlobalFileSystem().forEachArchive(LoadArchiveFileCaller());
+    globalOutputStream() << "Shaderplug: " << (const Unsigned)Shaderplug::archives.size() << " archives found.\n";
+  }
+
+  void CreateTagFile()
+  {
+    const char* shader_type = GlobalRadiant().getGameDescriptionKeyValue("shaders");
+
+    GetAllShaders();
+    globalOutputStream() << "Shaderplug: " << (const Unsigned)shaders.size() << " shaders found.\n";
+
+    if(string_equal(shader_type, "quake3"))
+    {
+      GetTextures("jpg");
+      GetTextures("tga");
+      GetTextures("png");
+
+      globalOutputStream() << "Shaderplug: " << (const Unsigned)textures.size() << " textures found.\n";
+    }
+
+    if(shaders.size() || textures.size() != 0)
+    {
+      globalOutputStream() << "Shaderplug: Creating XML tag file.\n";
+
+      TagBuilder.CreateXmlDocument();
+
+      std::set<std::string>::reverse_iterator r_iter;
+
+      for(r_iter = textures.rbegin(); r_iter != textures.rend(); ++r_iter)
+      {
+        TagBuilder.AddShaderNode(const_cast<char*>((*r_iter).c_str()), STOCK, TEXTURE);
+      }
+
+      for(r_iter = shaders.rbegin(); r_iter != shaders.rend(); ++r_iter)
+      {
+        TagBuilder.AddShaderNode(const_cast<char*>((*r_iter).c_str()), STOCK, SHADER);
+      }
+
+      // Get the tag file        
+      StringOutputStream tagFileStream(256);
+         tagFileStream << GlobalRadiant().getLocalRcPath() << SHADERTAG_FILE;
+      char* tagFile = tagFileStream.c_str();
+
+      char message[256];
+      strcpy(message, "Tag file saved to\n");
+      strcat(message, tagFile);
+      strcat(message, "\nPlease restart Radiant now.\n");
+
+      if(file_exists(tagFile))
+      {
+        EMessageBoxReturn result = GlobalRadiant().m_pfnMessageBox(GTK_WIDGET(g_window),
+            "WARNING! A tag file already exists! Overwrite it?", "Overwrite tag file?",
+            eMB_NOYES,
+            eMB_ICONWARNING);
+
+        if(result == eIDYES)
+        {
+          TagBuilder.SaveXmlDoc(tagFile);
+          GlobalRadiant().m_pfnMessageBox(GTK_WIDGET(g_window), message, "INFO", eMB_OK, eMB_ICONASTERISK);
+        }
+      } else {
+        TagBuilder.SaveXmlDoc(tagFile);
+        GlobalRadiant().m_pfnMessageBox(GTK_WIDGET(g_window), message, "INFO", eMB_OK, eMB_ICONASTERISK);
+      }
+    } else {
+      GlobalRadiant().m_pfnMessageBox(GTK_WIDGET(g_window),
+          "No shaders or textures found. No XML tag file created!\n"
+          "",
+          "ERROR",
+          eMB_OK,
+          eMB_ICONERROR);
+    }
+  }
+} // namespace
+
+class ShaderPluginModule
+{
+  _QERPluginTable m_plugin;
+public:
+  typedef _QERPluginTable Type;
+  STRING_CONSTANT(Name, "ShaderPlug");
+
+  ShaderPluginModule()
+  {
+    m_plugin.m_pfnQERPlug_Init = &Shaderplug::init;
+    m_plugin.m_pfnQERPlug_GetName = &Shaderplug::getName;
+    m_plugin.m_pfnQERPlug_GetCommandList = &Shaderplug::getCommandList;
+    m_plugin.m_pfnQERPlug_GetCommandTitleList = &Shaderplug::getCommandTitleList;
+    m_plugin.m_pfnQERPlug_Dispatch = &Shaderplug::dispatch;
+  }
+  _QERPluginTable* getTable()
+  {
+    return &m_plugin;
+  }
+};
+
+typedef SingletonModule<ShaderPluginModule, ShaderPlugPluginDependencies> SingletonShaderPluginModule;
+
+SingletonShaderPluginModule g_ShaderPluginModule;
+
+extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules(ModuleServer& server)
+{
+  initialiseModule(server);
+
+  g_ShaderPluginModule.selfRegister();
+}
+
+
+
+