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 LatchedValue<bool> g_useAlternativeTextureProjection( false, "Use alternative texture-projection (\"brush primitives\")" );
38 bool g_showAlternativeTextureProjectionOption = false;
39 bool g_brush_always_caulk;
41 bool getTextureLockEnabled(){
42 return g_brush_texturelock_enabled;
45 struct Face_SnapPlanes {
46 static void Export(const QuantiseFunc &self, const Callback<void(bool)> &returnz) {
47 returnz(self == quantiseInteger);
50 static void Import(QuantiseFunc &self, bool value) {
51 self = value ? quantiseInteger : quantiseFloating;
55 void Brush_constructPreferences( PreferencesPage& page ){
57 "", "Snap planes to integer grid",
58 make_property<Face_SnapPlanes>(Face::m_quantise)
61 "Default texture scale",
62 g_texdef_default_scale
64 if ( g_showAlternativeTextureProjectionOption ) {
66 "", "Use alternative texture-projection (\"brush primitives\")",
67 make_property(g_useAlternativeTextureProjection)
71 page.appendCheckBox( "",
72 "Always use caulk for new brushes",
76 void Brush_constructPage( PreferenceGroup& group ){
77 PreferencesPage page( group.createPage( "Brush", "Brush Settings" ) );
78 Brush_constructPreferences( page );
80 void Brush_registerPreferencesPage(){
81 PreferencesDialog_addSettingsPage( makeCallbackF(Brush_constructPage) );
84 void Brush_unlatchPreferences(){
85 Brush_toggleFormat( 0 );
88 void Brush_toggleFormat( int i ){
89 if ( g_showAlternativeTextureProjectionOption ) {
90 g_useAlternativeTextureProjection.m_value = g_useAlternativeTextureProjection.m_latched ^ i;
91 Brush::destroyStatic();
92 Brush::constructStatic( g_useAlternativeTextureProjection.m_value ? eBrushTypeQuake3BP : eBrushTypeQuake3 );
96 int Brush_toggleFormatCount(){
97 if ( g_showAlternativeTextureProjectionOption ) {
103 void Brush_Construct( EBrushType type ){
104 if ( type == eBrushTypeQuake3 ) {
105 g_showAlternativeTextureProjectionOption = true;
107 const char *value = g_pGameDescription->getKeyValue( "brush_primit" );
108 if ( !string_empty( value ) ) {
109 g_useAlternativeTextureProjection.m_latched = atoi( value );
112 GlobalPreferenceSystem().registerPreference(
113 "AlternativeTextureProjection",
114 make_property_string( g_useAlternativeTextureProjection.m_latched )
116 g_useAlternativeTextureProjection.useLatched();
118 if ( g_useAlternativeTextureProjection.m_value ) {
119 type = eBrushTypeQuake3BP;
123 GlobalPreferenceSystem().registerPreference(
125 make_property_string( g_brush_always_caulk )
129 Brush_registerCommands();
130 Brush_registerPreferencesPage();
132 BrushFilters_construct();
134 BrushClipPlane::constructStatic();
135 BrushInstance::constructStatic();
136 Brush::constructStatic( type );
138 Brush::m_maxWorldCoord = g_MaxWorldCoord;
139 BrushInstance::m_counter = &g_brushCount;
141 g_texdef_default_scale = 0.5f;
142 const char* value = g_pGameDescription->getKeyValue( "default_scale" );
143 if ( !string_empty( value ) ) {
144 float scale = static_cast<float>( atof( value ) );
146 g_texdef_default_scale = scale;
150 globalErrorStream() << "error parsing \"default_scale\" attribute\n";
154 GlobalPreferenceSystem().registerPreference( "TextureLock", make_property_string( g_brush_texturelock_enabled ) );
155 GlobalPreferenceSystem().registerPreference("BrushSnapPlanes", make_property_string<Face_SnapPlanes>(Face::m_quantise));
156 GlobalPreferenceSystem().registerPreference( "TexdefDefaultScale", make_property_string( g_texdef_default_scale ) );
158 GridStatus_getTextureLockEnabled = getTextureLockEnabled;
159 g_texture_lock_status_changed = makeCallbackF(GridStatus_onTextureLockEnabledChanged);
162 void Brush_Destroy(){
163 Brush::m_maxWorldCoord = 0;
164 BrushInstance::m_counter = 0;
166 Brush::destroyStatic();
167 BrushInstance::destroyStatic();
168 BrushClipPlane::destroyStatic();
171 void Brush_clipperColourChanged(){
172 BrushClipPlane::destroyStatic();
173 BrushClipPlane::constructStatic();
176 void BrushFaceData_fromFace( const BrushFaceDataCallback& callback, Face& face ){
177 _QERFaceData faceData;
178 faceData.m_p0 = face.getPlane().planePoints()[0];
179 faceData.m_p1 = face.getPlane().planePoints()[1];
180 faceData.m_p2 = face.getPlane().planePoints()[2];
181 faceData.m_shader = face.GetShader();
182 faceData.m_texdef = face.getTexdef().m_projection.m_texdef;
183 faceData.contents = face.getShader().m_flags.m_contentFlags;
184 faceData.flags = face.getShader().m_flags.m_surfaceFlags;
185 faceData.value = face.getShader().m_flags.m_value;
186 callback( faceData );
188 typedef ConstReferenceCaller<BrushFaceDataCallback, void(Face&), BrushFaceData_fromFace> BrushFaceDataFromFaceCaller;
189 typedef Callback<void(Face&)> FaceCallback;
191 class Quake3BrushCreator : public BrushCreator
194 scene::Node& createBrush(){
195 return ( new BrushNode )->node();
197 bool useAlternativeTextureProjection() const {
198 return g_useAlternativeTextureProjection.m_value;
200 void Brush_forEachFace( scene::Node& brush, const BrushFaceDataCallback& callback ){
201 ::Brush_forEachFace( *Node_getBrush( brush ), FaceCallback( BrushFaceDataFromFaceCaller( callback ) ) );
203 bool Brush_addFace( scene::Node& brush, const _QERFaceData& faceData ){
204 Node_getBrush( brush )->undoSave();
205 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;
209 Quake3BrushCreator g_Quake3BrushCreator;
211 BrushCreator& GetBrushCreator(){
212 return g_Quake3BrushCreator;
215 #include "modulesystem/singletonmodule.h"
216 #include "modulesystem/moduleregistry.h"
219 class BrushDependencies :
220 public GlobalRadiantModuleRef,
221 public GlobalSceneGraphModuleRef,
222 public GlobalShaderCacheModuleRef,
223 public GlobalSelectionModuleRef,
224 public GlobalOpenGLModuleRef,
225 public GlobalUndoModuleRef,
226 public GlobalFilterModuleRef
230 class BrushDoom3API : public TypeSystemRef
232 BrushCreator* m_brushdoom3;
234 typedef BrushCreator Type;
235 STRING_CONSTANT( Name, "doom3" );
238 Brush_Construct( eBrushTypeDoom3 );
240 m_brushdoom3 = &GetBrushCreator();
245 BrushCreator* getTable(){
250 typedef SingletonModule<BrushDoom3API, BrushDependencies> BrushDoom3Module;
251 typedef Static<BrushDoom3Module> StaticBrushDoom3Module;
252 StaticRegisterModule staticRegisterBrushDoom3( StaticBrushDoom3Module::instance() );
255 class BrushQuake4API : public TypeSystemRef
257 BrushCreator* m_brushquake4;
259 typedef BrushCreator Type;
260 STRING_CONSTANT( Name, "quake4" );
263 Brush_Construct( eBrushTypeQuake4 );
265 m_brushquake4 = &GetBrushCreator();
270 BrushCreator* getTable(){
271 return m_brushquake4;
275 typedef SingletonModule<BrushQuake4API, BrushDependencies> BrushQuake4Module;
276 typedef Static<BrushQuake4Module> StaticBrushQuake4Module;
277 StaticRegisterModule staticRegisterBrushQuake4( StaticBrushQuake4Module::instance() );
280 class BrushQuake3API : public TypeSystemRef
282 BrushCreator* m_brushquake3;
284 typedef BrushCreator Type;
285 STRING_CONSTANT( Name, "quake3" );
288 Brush_Construct( eBrushTypeQuake3 );
290 m_brushquake3 = &GetBrushCreator();
295 BrushCreator* getTable(){
296 return m_brushquake3;
300 typedef SingletonModule<BrushQuake3API, BrushDependencies> BrushQuake3Module;
301 typedef Static<BrushQuake3Module> StaticBrushQuake3Module;
302 StaticRegisterModule staticRegisterBrushQuake3( StaticBrushQuake3Module::instance() );
305 class BrushQuake2API : public TypeSystemRef
307 BrushCreator* m_brushquake2;
309 typedef BrushCreator Type;
310 STRING_CONSTANT( Name, "quake2" );
313 Brush_Construct( eBrushTypeQuake2 );
315 m_brushquake2 = &GetBrushCreator();
320 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" );
338 Brush_Construct( eBrushTypeQuake );
340 m_brushquake1 = &GetBrushCreator();
345 BrushCreator* getTable(){
346 return m_brushquake1;
350 typedef SingletonModule<BrushQuake1API, BrushDependencies> BrushQuake1Module;
351 typedef Static<BrushQuake1Module> StaticBrushQuake1Module;
352 StaticRegisterModule staticRegisterBrushQuake1( StaticBrushQuake1Module::instance() );
355 class BrushHalfLifeAPI : public TypeSystemRef
357 BrushCreator* m_brushhalflife;
359 typedef BrushCreator Type;
360 STRING_CONSTANT( Name, "halflife" );
363 Brush_Construct( eBrushTypeHalfLife );
365 m_brushhalflife = &GetBrushCreator();
370 BrushCreator* getTable(){
371 return m_brushhalflife;
375 typedef SingletonModule<BrushHalfLifeAPI, BrushDependencies> BrushHalfLifeModule;
376 typedef Static<BrushHalfLifeModule> StaticBrushHalfLifeModule;
377 StaticRegisterModule staticRegisterBrushHalfLife( StaticBrushHalfLifeModule::instance() );