]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - contrib/brushexport/plugin.cpp
Revert partially (auto) "reformat code! now the code is only ugly on the *inside*"
[xonotic/netradiant.git] / contrib / brushexport / plugin.cpp
1 /*
2    Copyright (C) 2006, Thomas Nitschke.
3    All Rights Reserved.
4
5    This file is part of GtkRadiant.
6
7    GtkRadiant is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    GtkRadiant is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with GtkRadiant; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21 #include "plugin.h"
22
23 #include "iplugin.h"
24 #include "qerplugin.h"
25
26 #include <gtk/gtk.h>
27
28 #include "debugging/debugging.h"
29 #include "string/string.h"
30 #include "modulesystem/singletonmodule.h"
31 #include "stream/textfilestream.h"
32 #include "stream/stringstream.h"
33 #include "gtkutil/messagebox.h"
34 #include "gtkutil/filechooser.h"
35
36 #include "ibrush.h"
37 #include "iscenegraph.h"
38 #include "iselection.h"
39 #include "ifilesystem.h"
40 #include "ifiletypes.h"
41
42 #include "support.h"
43
44 #include "typesystem.h"
45
46 void CreateWindow( void );
47 void DestroyWindow( void );
48 bool IsWindowOpen( void );
49
50 namespace BrushExport
51 {
52 ui::Window g_mainwnd{ui::null};
53
54 const char* init( void* hApp, void* pMainWidget ){
55         g_mainwnd = ui::Window::from(pMainWidget);
56         ASSERT_TRUE( g_mainwnd );
57         return "";
58 }
59 const char* getName(){
60         return "Brush export Plugin";
61 }
62 const char* getCommandList(){
63         return "Export selected as Wavefront Object;About";
64 }
65 const char* getCommandTitleList(){
66         return "";
67 }
68
69 void dispatch( const char* command, float* vMin, float* vMax, bool bSingleBrush ){
70         if ( string_equal( command, "About" ) ) {
71                 GlobalRadiant().m_pfnMessageBox( g_mainwnd, "Brushexport plugin v 2.0 by namespace (www.codecreator.net)\n"
72                                                                                                                                   "Enjoy!\n\nSend feedback to spam@codecreator.net", "About me...",
73                                                                                  eMB_OK,
74                                                                                  eMB_ICONDEFAULT );
75         }
76         else if ( string_equal( command, "Export selected as Wavefront Object" ) ) {
77                 if ( IsWindowOpen() ) {
78                         DestroyWindow();
79                 }
80                 CreateWindow();
81         }
82 }
83 }
84
85 class BrushExportDependencies :
86         public GlobalRadiantModuleRef,
87         public GlobalFiletypesModuleRef,
88         public GlobalBrushModuleRef,
89         public GlobalFileSystemModuleRef,
90         public GlobalSceneGraphModuleRef,
91         public GlobalSelectionModuleRef
92 {
93 public:
94 BrushExportDependencies( void )
95         : GlobalBrushModuleRef( GlobalRadiant().getRequiredGameDescriptionKeyValue( "brushtypes" ) )
96 {}
97 };
98
99 class BrushExportModule : public TypeSystemRef
100 {
101 _QERPluginTable m_plugin;
102 public:
103 typedef _QERPluginTable Type;
104 STRING_CONSTANT( Name, "brushexport2" );
105
106 BrushExportModule(){
107         m_plugin.m_pfnQERPlug_Init = &BrushExport::init;
108         m_plugin.m_pfnQERPlug_GetName = &BrushExport::getName;
109         m_plugin.m_pfnQERPlug_GetCommandList = &BrushExport::getCommandList;
110         m_plugin.m_pfnQERPlug_GetCommandTitleList = &BrushExport::getCommandTitleList;
111         m_plugin.m_pfnQERPlug_Dispatch = &BrushExport::dispatch;
112 }
113 _QERPluginTable* getTable(){
114         return &m_plugin;
115 }
116 };
117
118 typedef SingletonModule<BrushExportModule, BrushExportDependencies> SingletonBrushExportModule;
119 SingletonBrushExportModule g_BrushExportModule;
120
121 extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules( ModuleServer& server ){
122         initialiseModule( server );
123         g_BrushExportModule.selfRegister();
124 }