2 Copyright (C) 2001-2006, William Joseph.
5 This file is part of GtkRadiant.
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.
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.
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
22 #include "brushmodule.h"
24 #include "qerplugin.h"
26 #include "brushnode.h"
27 #include "brushmanip.h"
29 #include "preferencesystem.h"
34 #include "mainframe.h"
35 #include "preferences.h"
37 LatchedBool g_useAlternativeTextureProjection(false, "Use alternative texture-projection");
38 bool g_showAlternativeTextureProjectionOption = false;
40 bool getTextureLockEnabled()
42 return g_brush_texturelock_enabled;
45 void Face_importSnapPlanes(bool value)
47 Face::m_quantise = value ? quantiseInteger : quantiseFloating;
49 typedef FreeCaller1<bool, Face_importSnapPlanes> FaceImportSnapPlanesCaller;
51 void Face_exportSnapPlanes(const BoolImportCallback& importer)
53 importer(Face::m_quantise == quantiseInteger);
55 typedef FreeCaller1<const BoolImportCallback&, Face_exportSnapPlanes> FaceExportSnapPlanesCaller;
57 void Brush_constructPreferences(PreferencesPage& page)
60 "", "Snap planes to integer grid",
61 FaceImportSnapPlanesCaller(),
62 FaceExportSnapPlanesCaller()
65 "Default texture scale",
66 g_texdef_default_scale
68 if(g_showAlternativeTextureProjectionOption)
71 "", "Use alternative texture-projection",
72 LatchedBoolImportCaller(g_useAlternativeTextureProjection),
73 BoolExportCaller(g_useAlternativeTextureProjection.m_latched)
77 void Brush_constructPage(PreferenceGroup& group)
79 PreferencesPage page(group.createPage("Brush", "Brush Settings"));
80 Brush_constructPreferences(page);
82 void Brush_registerPreferencesPage()
84 PreferencesDialog_addSettingsPage(FreeCaller1<PreferenceGroup&, Brush_constructPage>());
88 void Brush_Construct(EBrushType type)
90 if(type == eBrushTypeQuake3)
92 g_showAlternativeTextureProjectionOption = true;
94 GlobalPreferenceSystem().registerPreference(
95 "AlternativeTextureProjection",
96 BoolImportStringCaller(g_useAlternativeTextureProjection.m_latched),
97 BoolExportStringCaller(g_useAlternativeTextureProjection.m_latched)
99 g_useAlternativeTextureProjection.useLatched();
101 if(g_useAlternativeTextureProjection.m_value)
103 type = eBrushTypeQuake3BP;
107 Brush_registerCommands();
108 Brush_registerPreferencesPage();
110 BrushFilters_construct();
112 BrushClipPlane::constructStatic();
113 BrushInstance::constructStatic();
114 Brush::constructStatic(type);
116 Brush::m_maxWorldCoord = g_MaxWorldCoord;
117 BrushInstance::m_counter = &g_brushCount;
119 g_texdef_default_scale = 0.5f;
120 const char* value = g_pGameDescription->getKeyValue("default_scale");
121 if(!string_empty(value))
123 float scale = static_cast<float>(atof(value));
126 g_texdef_default_scale = scale;
130 globalErrorStream() << "error parsing \"default_scale\" attribute\n";
134 GlobalPreferenceSystem().registerPreference("TextureLock", BoolImportStringCaller(g_brush_texturelock_enabled), BoolExportStringCaller(g_brush_texturelock_enabled));
135 GlobalPreferenceSystem().registerPreference("BrushSnapPlanes", makeBoolStringImportCallback(FaceImportSnapPlanesCaller()), makeBoolStringExportCallback(FaceExportSnapPlanesCaller()));
136 GlobalPreferenceSystem().registerPreference("TexdefDefaultScale", FloatImportStringCaller(g_texdef_default_scale), FloatExportStringCaller(g_texdef_default_scale));
138 GridStatus_getTextureLockEnabled = getTextureLockEnabled;
139 g_texture_lock_status_changed = FreeCaller<GridStatus_onTextureLockEnabledChanged>();
144 Brush::m_maxWorldCoord = 0;
145 BrushInstance::m_counter = 0;
147 Brush::destroyStatic();
148 BrushInstance::destroyStatic();
149 BrushClipPlane::destroyStatic();
152 void Brush_clipperColourChanged()
154 BrushClipPlane::destroyStatic();
155 BrushClipPlane::constructStatic();
158 void BrushFaceData_fromFace(const BrushFaceDataCallback& callback, Face& face)
160 _QERFaceData faceData;
161 faceData.m_p0 = face.getPlane().planePoints()[0];
162 faceData.m_p1 = face.getPlane().planePoints()[1];
163 faceData.m_p2 = face.getPlane().planePoints()[2];
164 faceData.m_shader = face.GetShader();
165 faceData.m_texdef = face.getTexdef().m_projection.m_texdef;
166 faceData.contents = face.getShader().m_flags.m_contentFlags;
167 faceData.flags = face.getShader().m_flags.m_surfaceFlags;
168 faceData.value = face.getShader().m_flags.m_value;
171 typedef ConstReferenceCaller1<BrushFaceDataCallback, Face&, BrushFaceData_fromFace> BrushFaceDataFromFaceCaller;
172 typedef Callback1<Face&> FaceCallback;
174 class Quake3BrushCreator : public BrushCreator
177 scene::Node& createBrush()
179 return (new BrushNode)->node();
181 bool useAlternativeTextureProjection() const
183 return g_useAlternativeTextureProjection.m_value;
185 void Brush_forEachFace(scene::Node& brush, const BrushFaceDataCallback& callback)
187 ::Brush_forEachFace(*Node_getBrush(brush), FaceCallback(BrushFaceDataFromFaceCaller(callback)));
189 bool Brush_addFace(scene::Node& brush, const _QERFaceData& faceData)
191 Node_getBrush(brush)->undoSave();
192 return Node_getBrush(brush)->addPlane(faceData.m_p0, faceData.m_p1, faceData.m_p2, faceData.m_shader, TextureProjection(faceData.m_texdef, brushprimit_texdef_t(), Vector3(0, 0, 0), Vector3(0, 0, 0))) != 0;
196 Quake3BrushCreator g_Quake3BrushCreator;
198 BrushCreator& GetBrushCreator()
200 return g_Quake3BrushCreator;
203 #include "modulesystem/singletonmodule.h"
204 #include "modulesystem/moduleregistry.h"
207 class BrushDependencies :
208 public GlobalRadiantModuleRef,
209 public GlobalSceneGraphModuleRef,
210 public GlobalShaderCacheModuleRef,
211 public GlobalSelectionModuleRef,
212 public GlobalOpenGLModuleRef,
213 public GlobalUndoModuleRef,
214 public GlobalFilterModuleRef
218 class BrushDoom3API : public TypeSystemRef
220 BrushCreator* m_brushdoom3;
222 typedef BrushCreator Type;
223 STRING_CONSTANT(Name, "doom3");
227 Brush_Construct(eBrushTypeDoom3);
229 m_brushdoom3 = &GetBrushCreator();
235 BrushCreator* getTable()
241 typedef SingletonModule<BrushDoom3API, BrushDependencies> BrushDoom3Module;
242 typedef Static<BrushDoom3Module> StaticBrushDoom3Module;
243 StaticRegisterModule staticRegisterBrushDoom3(StaticBrushDoom3Module::instance());
246 class BrushQuake4API : public TypeSystemRef
248 BrushCreator* m_brushquake4;
250 typedef BrushCreator Type;
251 STRING_CONSTANT(Name, "quake4");
255 Brush_Construct(eBrushTypeQuake4);
257 m_brushquake4 = &GetBrushCreator();
263 BrushCreator* getTable()
265 return m_brushquake4;
269 typedef SingletonModule<BrushQuake4API, BrushDependencies> BrushQuake4Module;
270 typedef Static<BrushQuake4Module> StaticBrushQuake4Module;
271 StaticRegisterModule staticRegisterBrushQuake4(StaticBrushQuake4Module::instance());
274 class BrushQuake3API : public TypeSystemRef
276 BrushCreator* m_brushquake3;
278 typedef BrushCreator Type;
279 STRING_CONSTANT(Name, "quake3");
283 Brush_Construct(eBrushTypeQuake3);
285 m_brushquake3 = &GetBrushCreator();
291 BrushCreator* getTable()
293 return m_brushquake3;
297 typedef SingletonModule<BrushQuake3API, BrushDependencies> BrushQuake3Module;
298 typedef Static<BrushQuake3Module> StaticBrushQuake3Module;
299 StaticRegisterModule staticRegisterBrushQuake3(StaticBrushQuake3Module::instance());
302 class BrushQuake2API : public TypeSystemRef
304 BrushCreator* m_brushquake2;
306 typedef BrushCreator Type;
307 STRING_CONSTANT(Name, "quake2");
311 Brush_Construct(eBrushTypeQuake2);
313 m_brushquake2 = &GetBrushCreator();
319 BrushCreator* getTable()
321 return m_brushquake2;
325 typedef SingletonModule<BrushQuake2API, BrushDependencies> BrushQuake2Module;
326 typedef Static<BrushQuake2Module> StaticBrushQuake2Module;
327 StaticRegisterModule staticRegisterBrushQuake2(StaticBrushQuake2Module::instance());
330 class BrushQuake1API : public TypeSystemRef
332 BrushCreator* m_brushquake1;
334 typedef BrushCreator Type;
335 STRING_CONSTANT(Name, "quake");
339 Brush_Construct(eBrushTypeQuake);
341 m_brushquake1 = &GetBrushCreator();
347 BrushCreator* getTable()
349 return m_brushquake1;
353 typedef SingletonModule<BrushQuake1API, BrushDependencies> BrushQuake1Module;
354 typedef Static<BrushQuake1Module> StaticBrushQuake1Module;
355 StaticRegisterModule staticRegisterBrushQuake1(StaticBrushQuake1Module::instance());
358 class BrushHalfLifeAPI : public TypeSystemRef
360 BrushCreator* m_brushhalflife;
362 typedef BrushCreator Type;
363 STRING_CONSTANT(Name, "halflife");
367 Brush_Construct(eBrushTypeHalfLife);
369 m_brushhalflife = &GetBrushCreator();
375 BrushCreator* getTable()
377 return m_brushhalflife;
381 typedef SingletonModule<BrushHalfLifeAPI, BrushDependencies> BrushHalfLifeModule;
382 typedef Static<BrushHalfLifeModule> StaticBrushHalfLifeModule;
383 StaticRegisterModule staticRegisterBrushHalfLife(StaticBrushHalfLifeModule::instance());