]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/patchmodule.cpp
allow undo “make detail/structural”, <3 @SpiKe, thanks @Garux, fix #76
[xonotic/netradiant.git] / radiant / patchmodule.cpp
1 /*
2    Copyright (C) 2001-2006, William Joseph.
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
22 #include "patchmodule.h"
23
24 #include "qerplugin.h"
25 #include "ipatch.h"
26
27 #include "patch.h"
28 #include "patchmanip.h"
29
30 namespace {
31     std::size_t g_patchModuleCount = 0;
32 }
33
34 void Patch_Construct(EPatchType type)
35 {
36     if (++g_patchModuleCount != 1) {
37         return;
38     }
39
40     PatchFilters_construct();
41
42     PatchPreferences_construct();
43
44     Patch_registerPreferencesPage();
45
46     Patch::constructStatic(type);
47     PatchInstance::constructStatic();
48
49     if (type == ePatchTypeDoom3) {
50         MAX_PATCH_WIDTH = MAX_PATCH_HEIGHT = 99;
51     } else {
52         MAX_PATCH_WIDTH = MAX_PATCH_HEIGHT = 31; // matching q3map2
53     }
54 }
55
56 void Patch_Destroy()
57 {
58     if (--g_patchModuleCount != 0) {
59         return;
60     }
61
62     Patch::destroyStatic();
63     PatchInstance::destroyStatic();
64 }
65
66 class CommonPatchCreator : public PatchCreator {
67 public:
68     void Patch_undoSave(scene::Node &patch) const
69     {
70         Node_getPatch(patch)->undoSave();
71     }
72
73     void Patch_resize(scene::Node &patch, std::size_t width, std::size_t height) const
74     {
75         Node_getPatch(patch)->setDims(width, height);
76     }
77
78     PatchControlMatrix Patch_getControlPoints(scene::Node &node) const
79     {
80         Patch &patch = *Node_getPatch(node);
81         return PatchControlMatrix(patch.getHeight(), patch.getWidth(), patch.getControlPoints().data());
82     }
83
84     void Patch_controlPointsChanged(scene::Node &patch) const
85     {
86         return Node_getPatch(patch)->controlPointsChanged();
87     }
88
89     const char *Patch_getShader(scene::Node &patch) const
90     {
91         return Node_getPatch(patch)->GetShader();
92     }
93
94     void Patch_setShader(scene::Node &patch, const char *shader) const
95     {
96         Node_getPatch(patch)->SetShader(shader);
97     }
98 };
99
100 class Quake3PatchCreator : public CommonPatchCreator {
101 public:
102     scene::Node &createPatch()
103     {
104         return (new PatchNodeQuake3())->node();
105     }
106 };
107
108 Quake3PatchCreator g_Quake3PatchCreator;
109
110 PatchCreator &GetQuake3PatchCreator()
111 {
112     return g_Quake3PatchCreator;
113 }
114
115 class Doom3PatchCreator : public CommonPatchCreator {
116 public:
117     scene::Node &createPatch()
118     {
119         return (new PatchNodeDoom3(true))->node();
120     }
121 };
122
123 Doom3PatchCreator g_Doom3PatchCreator;
124
125 PatchCreator &GetDoom3PatchCreator()
126 {
127     return g_Doom3PatchCreator;
128 }
129
130 class Doom3PatchDef2Creator : public CommonPatchCreator {
131 public:
132     scene::Node &createPatch()
133     {
134         return (new PatchNodeDoom3())->node();
135     }
136 };
137
138 Doom3PatchDef2Creator g_Doom3PatchDef2Creator;
139
140 PatchCreator &GetDoom3PatchDef2Creator()
141 {
142     return g_Doom3PatchDef2Creator;
143 }
144
145 #include "modulesystem/singletonmodule.h"
146 #include "modulesystem/moduleregistry.h"
147
148 class PatchDependencies :
149         public GlobalRadiantModuleRef,
150         public GlobalSceneGraphModuleRef,
151         public GlobalShaderCacheModuleRef,
152         public GlobalSelectionModuleRef,
153         public GlobalOpenGLModuleRef,
154         public GlobalUndoModuleRef,
155         public GlobalFilterModuleRef {
156 };
157
158 class PatchQuake3API : public TypeSystemRef {
159     PatchCreator *m_patchquake3;
160 public:
161     typedef PatchCreator Type;
162
163     STRING_CONSTANT(Name, "quake3");
164
165     PatchQuake3API()
166     {
167         Patch_Construct(ePatchTypeQuake3);
168
169         m_patchquake3 = &GetQuake3PatchCreator();
170         g_patchCreator = m_patchquake3;
171     }
172
173     ~PatchQuake3API()
174     {
175         Patch_Destroy();
176     }
177
178     PatchCreator *getTable()
179     {
180         return m_patchquake3;
181     }
182 };
183
184 typedef SingletonModule<PatchQuake3API, PatchDependencies> PatchQuake3Module;
185 typedef Static<PatchQuake3Module> StaticPatchQuake3Module;
186 StaticRegisterModule staticRegisterPatchQuake3(StaticPatchQuake3Module::instance());
187
188
189 class PatchDoom3API : public TypeSystemRef {
190     PatchCreator *m_patchdoom3;
191 public:
192     typedef PatchCreator Type;
193
194     STRING_CONSTANT(Name, "doom3");
195
196     PatchDoom3API()
197     {
198         Patch_Construct(ePatchTypeDoom3);
199
200         m_patchdoom3 = &GetDoom3PatchCreator();
201     }
202
203     ~PatchDoom3API()
204     {
205         Patch_Destroy();
206     }
207
208     PatchCreator *getTable()
209     {
210         return m_patchdoom3;
211     }
212 };
213
214 typedef SingletonModule<PatchDoom3API, PatchDependencies> PatchDoom3Module;
215 typedef Static<PatchDoom3Module> StaticPatchDoom3Module;
216 StaticRegisterModule staticRegisterPatchDoom3(StaticPatchDoom3Module::instance());
217
218
219 class PatchDef2Doom3API : public TypeSystemRef {
220     PatchCreator *m_patchdef2doom3;
221 public:
222     typedef PatchCreator Type;
223
224     STRING_CONSTANT(Name, "def2doom3");
225
226     PatchDef2Doom3API()
227     {
228         Patch_Construct(ePatchTypeDoom3);
229
230         m_patchdef2doom3 = &GetDoom3PatchDef2Creator();
231         g_patchCreator = m_patchdef2doom3;
232     }
233
234     ~PatchDef2Doom3API()
235     {
236         Patch_Destroy();
237     }
238
239     PatchCreator *getTable()
240     {
241         return m_patchdef2doom3;
242     }
243 };
244
245 typedef SingletonModule<PatchDef2Doom3API, PatchDependencies> PatchDef2Doom3Module;
246 typedef Static<PatchDef2Doom3Module> StaticPatchDef2Doom3Module;
247 StaticRegisterModule staticRegisterPatchDef2Doom3(StaticPatchDef2Doom3Module::instance());