X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fnetradiant.git;a=blobdiff_plain;f=radiant%2Fbrushmanip.cpp;h=b2acc1faeda76e52de8817f12e15140969fc3da5;hp=940c6f649035bc939d770a3d8e34db5644633f3f;hb=72ce262ae89739330d16052b9548aad5cbe5c89d;hpb=12b372f89ce109a4db9d510884fbe7d05af79870 diff --git a/radiant/brushmanip.cpp b/radiant/brushmanip.cpp index 940c6f64..b2acc1fa 100644 --- a/radiant/brushmanip.cpp +++ b/radiant/brushmanip.cpp @@ -37,14 +37,12 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include - void Brush_ConstructCuboid(Brush& brush, const AABB& bounds, const char* shader, const TextureProjection& projection) { const unsigned char box[3][2] = { { 0, 1 }, { 2, 0 }, { 1, 2 } }; Vector3 mins(vector3_subtracted(bounds.origin, bounds.extents)); Vector3 maxs(vector3_added(bounds.origin, bounds.extents)); - brush.undoSave(); brush.clear(); brush.reserve(6); @@ -107,7 +105,6 @@ void Brush_ConstructPrism(Brush& brush, const AABB& bounds, std::size_t sides, i return; } - brush.undoSave(); brush.clear(); brush.reserve(sides+2); @@ -180,7 +177,6 @@ void Brush_ConstructCone(Brush& brush, const AABB& bounds, std::size_t sides, co return; } - brush.undoSave(); brush.clear(); brush.reserve(sides+1); @@ -235,7 +231,6 @@ void Brush_ConstructSphere(Brush& brush, const AABB& bounds, std::size_t sides, return; } - brush.undoSave(); brush.clear(); brush.reserve(sides*sides); @@ -362,166 +357,14 @@ void ConstructRegionBrushes(scene::Node* brushes[6], const Vector3& region_mins, } -class BrushForEachFace -{ - const BrushInstanceVisitor& m_visitor; -public: - BrushForEachFace(const BrushInstanceVisitor& visitor) : m_visitor(visitor) - { - } - void operator()(BrushInstance& brush) const - { - brush.forEachFaceInstance(m_visitor); - } -}; - -template -class FaceVisitAll : public BrushInstanceVisitor -{ - const Visitor& m_visitor; -public: - FaceVisitAll(const Visitor& visitor) - : m_visitor(visitor) - { - } - void visit(FaceInstance& face) const - { - m_visitor.visit(face.getFace()); - } -}; - -template -class FaceInstanceVisitAll : public BrushInstanceVisitor -{ - const Visitor& m_visitor; -public: - FaceInstanceVisitAll(const Visitor& visitor) - : m_visitor(visitor) - { - } - void visit(FaceInstance& face) const - { - m_visitor.visit(face); - } -}; - -template -class FaceVisitSelected : public BrushInstanceVisitor -{ - const Visitor& m_visitor; -public: - FaceVisitSelected(const Visitor& visitor) - : m_visitor(visitor) - { - } - void visit(FaceInstance& face) const - { - if(face.isSelected(SelectionSystem::eFace)) - { - m_visitor.visit(face.getFace()); - } - } -}; - -template -inline void Scene_forEachBrush(scene::Graph& graph, const Functor& functor) -{ - graph.traverse(InstanceWalker< InstanceApply >(functor)); -} - -template -class InstanceIfVisible : public Functor -{ -public: - InstanceIfVisible(const Functor& functor) : Functor(functor) - { - } - void operator()(scene::Instance& instance) - { - if(instance.path().top().get().visible()) - { - Functor::operator()(instance); - } - } -}; - -template -class BrushVisibleWalker : public scene::Graph::Walker -{ - const Functor& m_functor; -public: - BrushVisibleWalker(const Functor& functor) : m_functor(functor) - { - } - bool pre(const scene::Path& path, scene::Instance& instance) const - { - if(path.top().get().visible()) - { - BrushInstance* brush = Instance_getBrush(instance); - if(brush != 0) - { - m_functor(*brush); - } - } - return true; - } -}; - -template -inline void Scene_forEachVisibleBrush(scene::Graph& graph, const Functor& functor) -{ - graph.traverse(BrushVisibleWalker(functor)); -} - -template -inline void Scene_ForEachBrush_ForEachFace(scene::Graph& graph, const Visitor& visitor) -{ - Scene_forEachBrush(graph, BrushForEachFace(FaceVisitAll(visitor))); -} - -template -inline void Scene_ForEachSelectedBrush_ForEachFace(scene::Graph& graph, const Visitor& visitor) -{ - Scene_forEachSelectedBrush(BrushForEachFace(FaceVisitAll(visitor))); -} - -template -inline void Scene_ForEachSelectedBrush_ForEachFaceInstance(scene::Graph& graph, const Visitor& visitor) -{ - Scene_forEachSelectedBrush(BrushForEachFace(FaceInstanceVisitAll(visitor))); -} - -template -class FaceVisitorWrapper -{ - Visitor& m_visitor; -public: - FaceVisitorWrapper(Visitor& visitor) : m_visitor(visitor) - { - } - - void operator()(FaceInstance& faceInstance) - { - m_visitor.visit(faceInstance.getFace()); - } -}; - -template -inline void Scene_ForEachSelectedBrushFace(scene::Graph& graph, Visitor& faceVisitor) -{ - g_SelectedFaceInstances.foreach(FaceVisitorWrapper(faceVisitor)); -} - - - -class FaceSetTexdefVisitor +class FaceSetTexdef { const TextureProjection& m_projection; public: - FaceSetTexdefVisitor(const TextureProjection& projection) : m_projection(projection) + FaceSetTexdef(const TextureProjection& projection) : m_projection(projection) { } - void visit(Face& face) const + void operator()(Face& face) const { face.SetTexdef(m_projection); } @@ -529,26 +372,25 @@ public: void Scene_BrushSetTexdef_Selected(scene::Graph& graph, const TextureProjection& projection) { - Scene_ForEachSelectedBrush_ForEachFace(graph, FaceSetTexdefVisitor(projection)); + Scene_ForEachSelectedBrush_ForEachFace(graph, FaceSetTexdef(projection)); SceneChangeNotify(); } void Scene_BrushSetTexdef_Component_Selected(scene::Graph& graph, const TextureProjection& projection) { - FaceSetTexdefVisitor visitor(projection); - Scene_ForEachSelectedBrushFace(graph, visitor); + Scene_ForEachSelectedBrushFace(graph, FaceSetTexdef(projection)); SceneChangeNotify(); } -class FaceSetFlagsVisitor +class FaceSetFlags { const ContentsFlagsValue& m_projection; public: - FaceSetFlagsVisitor(const ContentsFlagsValue& flags) : m_projection(flags) + FaceSetFlags(const ContentsFlagsValue& flags) : m_projection(flags) { } - void visit(Face& face) const + void operator()(Face& face) const { face.SetFlags(m_projection); } @@ -556,25 +398,24 @@ public: void Scene_BrushSetFlags_Selected(scene::Graph& graph, const ContentsFlagsValue& flags) { - Scene_ForEachSelectedBrush_ForEachFace(graph, FaceSetFlagsVisitor(flags)); + Scene_ForEachSelectedBrush_ForEachFace(graph, FaceSetFlags(flags)); SceneChangeNotify(); } void Scene_BrushSetFlags_Component_Selected(scene::Graph& graph, const ContentsFlagsValue& flags) { - FaceSetFlagsVisitor visitor(flags); - Scene_ForEachSelectedBrushFace(graph, visitor); + Scene_ForEachSelectedBrushFace(graph, FaceSetFlags(flags)); SceneChangeNotify(); } -class FaceShiftTexdefVisitor +class FaceShiftTexdef { float m_s, m_t; public: - FaceShiftTexdefVisitor(float s, float t) : m_s(s), m_t(t) + FaceShiftTexdef(float s, float t) : m_s(s), m_t(t) { } - void visit(Face& face) const + void operator()(Face& face) const { face.ShiftTexdef(m_s, m_t); } @@ -582,25 +423,24 @@ public: void Scene_BrushShiftTexdef_Selected(scene::Graph& graph, float s, float t) { - Scene_ForEachSelectedBrush_ForEachFace(graph, FaceShiftTexdefVisitor(s, t)); + Scene_ForEachSelectedBrush_ForEachFace(graph, FaceShiftTexdef(s, t)); SceneChangeNotify(); } void Scene_BrushShiftTexdef_Component_Selected(scene::Graph& graph, float s, float t) { - FaceShiftTexdefVisitor visitor(s, t); - Scene_ForEachSelectedBrushFace(graph, visitor); + Scene_ForEachSelectedBrushFace(graph, FaceShiftTexdef(s, t)); SceneChangeNotify(); } -class FaceScaleTexdefVisitor +class FaceScaleTexdef { float m_s, m_t; public: - FaceScaleTexdefVisitor(float s, float t) : m_s(s), m_t(t) + FaceScaleTexdef(float s, float t) : m_s(s), m_t(t) { } - void visit(Face& face) const + void operator()(Face& face) const { face.ScaleTexdef(m_s, m_t); } @@ -608,25 +448,24 @@ public: void Scene_BrushScaleTexdef_Selected(scene::Graph& graph, float s, float t) { - Scene_ForEachSelectedBrush_ForEachFace(graph, FaceScaleTexdefVisitor(s, t)); + Scene_ForEachSelectedBrush_ForEachFace(graph, FaceScaleTexdef(s, t)); SceneChangeNotify(); } void Scene_BrushScaleTexdef_Component_Selected(scene::Graph& graph, float s, float t) { - FaceScaleTexdefVisitor visitor(s, t); - Scene_ForEachSelectedBrushFace(graph, visitor); + Scene_ForEachSelectedBrushFace(graph, FaceScaleTexdef(s, t)); SceneChangeNotify(); } -class FaceRotateTexdefVisitor +class FaceRotateTexdef { float m_angle; public: - FaceRotateTexdefVisitor(float angle) : m_angle(angle) + FaceRotateTexdef(float angle) : m_angle(angle) { } - void visit(Face& face) const + void operator()(Face& face) const { face.RotateTexdef(m_angle); } @@ -634,24 +473,23 @@ public: void Scene_BrushRotateTexdef_Selected(scene::Graph& graph, float angle) { - Scene_ForEachSelectedBrush_ForEachFace(graph, FaceRotateTexdefVisitor(angle)); + Scene_ForEachSelectedBrush_ForEachFace(graph, FaceRotateTexdef(angle)); SceneChangeNotify(); } void Scene_BrushRotateTexdef_Component_Selected(scene::Graph& graph, float angle) { - FaceRotateTexdefVisitor visitor(angle); - Scene_ForEachSelectedBrushFace(graph, visitor); + Scene_ForEachSelectedBrushFace(graph, FaceRotateTexdef(angle)); SceneChangeNotify(); } -class FaceSetShaderVisitor +class FaceSetShader { const char* m_name; public: - FaceSetShaderVisitor(const char* name) : m_name(name) {} - void visit(Face& face) const + FaceSetShader(const char* name) : m_name(name) {} + void operator()(Face& face) const { face.SetShader(m_name); } @@ -659,25 +497,24 @@ public: void Scene_BrushSetShader_Selected(scene::Graph& graph, const char* name) { - Scene_ForEachSelectedBrush_ForEachFace(graph, FaceSetShaderVisitor(name)); + Scene_ForEachSelectedBrush_ForEachFace(graph, FaceSetShader(name)); SceneChangeNotify(); } void Scene_BrushSetShader_Component_Selected(scene::Graph& graph, const char* name) { - FaceSetShaderVisitor visitor(name); - Scene_ForEachSelectedBrushFace(graph, visitor); + Scene_ForEachSelectedBrushFace(graph, FaceSetShader(name)); SceneChangeNotify(); } -class FaceSetDetailVisitor +class FaceSetDetail { bool m_detail; public: - FaceSetDetailVisitor(bool detail) : m_detail(detail) + FaceSetDetail(bool detail) : m_detail(detail) { } - void visit(Face& face) const + void operator()(Face& face) const { face.setDetail(m_detail); } @@ -685,7 +522,7 @@ public: void Scene_BrushSetDetail_Selected(scene::Graph& graph, bool detail) { - Scene_ForEachSelectedBrush_ForEachFace(graph, FaceSetDetailVisitor(detail)); + Scene_ForEachSelectedBrush_ForEachFace(graph, FaceSetDetail(detail)); SceneChangeNotify(); } @@ -699,15 +536,15 @@ bool Face_FindReplaceShader(Face& face, const char* find, const char* replace) return false; } -class FaceFindReplaceShaderVisitor +class FaceFindReplaceShader { const char* m_find; const char* m_replace; public: - FaceFindReplaceShaderVisitor(const char* find, const char* replace) : m_find(find), m_replace(replace) + FaceFindReplaceShader(const char* find, const char* replace) : m_find(find), m_replace(replace) { } - void visit(Face& face) const + void operator()(Face& face) const { Face_FindReplaceShader(face, m_find, m_replace); } @@ -715,29 +552,28 @@ public: void Scene_BrushFindReplaceShader(scene::Graph& graph, const char* find, const char* replace) { - Scene_ForEachBrush_ForEachFace(graph, FaceFindReplaceShaderVisitor(find, replace)); + Scene_ForEachBrush_ForEachFace(graph, FaceFindReplaceShader(find, replace)); } void Scene_BrushFindReplaceShader_Selected(scene::Graph& graph, const char* find, const char* replace) { - Scene_ForEachSelectedBrush_ForEachFace(graph, FaceFindReplaceShaderVisitor(find, replace)); + Scene_ForEachSelectedBrush_ForEachFace(graph, FaceFindReplaceShader(find, replace)); } void Scene_BrushFindReplaceShader_Component_Selected(scene::Graph& graph, const char* find, const char* replace) { - FaceFindReplaceShaderVisitor visitor(find, replace); - Scene_ForEachSelectedBrushFace(graph, visitor); + Scene_ForEachSelectedBrushFace(graph, FaceFindReplaceShader(find, replace)); } -class FaceFitTextureVisitor +class FaceFitTexture { float m_s_repeat, m_t_repeat; public: - FaceFitTextureVisitor(float s_repeat, float t_repeat) : m_s_repeat(s_repeat), m_t_repeat(t_repeat) + FaceFitTexture(float s_repeat, float t_repeat) : m_s_repeat(s_repeat), m_t_repeat(t_repeat) { } - void visit(Face& face) const + void operator()(Face& face) const { face.FitTexture(m_s_repeat, m_t_repeat); } @@ -745,17 +581,22 @@ public: void Scene_BrushFitTexture_Selected(scene::Graph& graph, float s_repeat, float t_repeat) { - Scene_ForEachSelectedBrush_ForEachFace(graph, FaceFitTextureVisitor(s_repeat, t_repeat)); + Scene_ForEachSelectedBrush_ForEachFace(graph, FaceFitTexture(s_repeat, t_repeat)); SceneChangeNotify(); } void Scene_BrushFitTexture_Component_Selected(scene::Graph& graph, float s_repeat, float t_repeat) { - FaceFitTextureVisitor visitor(s_repeat, t_repeat); - Scene_ForEachSelectedBrushFace(graph, visitor); + Scene_ForEachSelectedBrushFace(graph, FaceFitTexture(s_repeat, t_repeat)); SceneChangeNotify(); } +TextureProjection g_defaultTextureProjection; +const TextureProjection& TextureTransform_getDefault() +{ + TexDef_Construct_Default(g_defaultTextureProjection); + return g_defaultTextureProjection; +} void Scene_BrushConstructPrefab(scene::Graph& graph, EBrushPrefab type, std::size_t sides, const char* shader) { @@ -766,10 +607,8 @@ void Scene_BrushConstructPrefab(scene::Graph& graph, EBrushPrefab type, std::siz Brush* brush = Node_getBrush(path.top()); if(brush != 0) { - AABB bounds = brush->localAABB(); - TextureProjection projection; - TexDef_Construct_Default(projection); - Brush_ConstructPrefab(*brush, type, bounds, sides, shader, projection); + AABB bounds = brush->localAABB(); // copy bounds because the brush will be modified + Brush_ConstructPrefab(*brush, type, bounds, sides, shader, TextureTransform_getDefault()); SceneChangeNotify(); } } @@ -784,9 +623,7 @@ void Scene_BrushResize_Selected(scene::Graph& graph, const AABB& bounds, const c Brush* brush = Node_getBrush(path.top()); if(brush != 0) { - TextureProjection projection; - TexDef_Construct_Default(projection); - Brush_ConstructCuboid(*brush, bounds, shader, projection); + Brush_ConstructCuboid(*brush, bounds, shader, TextureTransform_getDefault()); SceneChangeNotify(); } } @@ -831,15 +668,15 @@ void Scene_BrushSelectByShader(scene::Graph& graph, const char* name) graph.traverse(BrushSelectByShaderWalker(name)); } -class FaceSelectByShaderVisitor : public BrushInstanceVisitor +class FaceSelectByShader { const char* m_name; public: - FaceSelectByShaderVisitor(const char* name) + FaceSelectByShader(const char* name) : m_name(name) { } - void visit(FaceInstance& face) const + void operator()(FaceInstance& face) const { if(shader_equal(face.getFace().GetShader(), m_name)) { @@ -850,24 +687,24 @@ public: void Scene_BrushSelectByShader_Component(scene::Graph& graph, const char* name) { - Scene_ForEachSelectedBrush_ForEachFaceInstance(graph, FaceSelectByShaderVisitor(name)); + Scene_ForEachSelectedBrush_ForEachFaceInstance(graph, FaceSelectByShader(name)); } -class FaceGetTexdefVisitor +class FaceGetTexdef { TextureProjection& m_projection; mutable bool m_done; public: - FaceGetTexdefVisitor(TextureProjection& projection) + FaceGetTexdef(TextureProjection& projection) : m_projection(projection), m_done(false) { } - void visit(Face& face) const + void operator()(Face& face) const { if(!m_done) { m_done = true; - FaceTexdef_getTexdef(face.getTexdef(), m_projection); + face.GetTexdef(m_projection); } } }; @@ -875,8 +712,7 @@ public: void Scene_BrushGetTexdef_Selected(scene::Graph& graph, TextureProjection& projection) { - FaceGetTexdefVisitor visitor(projection); - Scene_ForEachSelectedBrush_ForEachFace(graph, visitor); + Scene_ForEachSelectedBrush_ForEachFace(graph, FaceGetTexdef(projection)); } void Scene_BrushGetTexdef_Component_Selected(scene::Graph& graph, TextureProjection& projection) @@ -885,30 +721,40 @@ void Scene_BrushGetTexdef_Component_Selected(scene::Graph& graph, TextureProject if(!g_SelectedFaceInstances.empty()) { FaceInstance& faceInstance = g_SelectedFaceInstances.last(); - FaceTexdef_getTexdef(faceInstance.getFace().getTexdef(), projection); + faceInstance.getFace().GetTexdef(projection); } #else - FaceGetTexdefVisitor visitor(projection); + FaceGetTexdef visitor(projection); Scene_ForEachSelectedBrushFace(graph, visitor); #endif } +void Scene_BrushGetShaderSize_Component_Selected(scene::Graph& graph, size_t& width, size_t& height) +{ + if(!g_SelectedFaceInstances.empty()) + { + FaceInstance& faceInstance = g_SelectedFaceInstances.last(); + width = faceInstance.getFace().getShader().width(); + height = faceInstance.getFace().getShader().height(); + } +} -class FaceGetFlagsVisitor + +class FaceGetFlags { ContentsFlagsValue& m_flags; mutable bool m_done; public: - FaceGetFlagsVisitor(ContentsFlagsValue& flags) + FaceGetFlags(ContentsFlagsValue& flags) : m_flags(flags), m_done(false) { } - void visit(Face& face) const + void operator()(Face& face) const { if(!m_done) { m_done = true; - FaceShader_getFlags(face.getShader(), m_flags); + face.GetFlags(m_flags); } } }; @@ -916,8 +762,18 @@ public: void Scene_BrushGetFlags_Selected(scene::Graph& graph, ContentsFlagsValue& flags) { - FaceGetFlagsVisitor visitor(flags); - Scene_ForEachSelectedBrush_ForEachFace(graph, visitor); +#if 1 + if(GlobalSelectionSystem().countSelected() != 0) + { + BrushInstance* brush = Instance_getBrush(GlobalSelectionSystem().ultimateSelected()); + if(brush != 0) + { + Brush_forEachFace(*brush, FaceGetFlags(flags)); + } + } +#else + Scene_ForEachSelectedBrush_ForEachFace(graph, FaceGetFlags(flags)); +#endif } void Scene_BrushGetFlags_Component_Selected(scene::Graph& graph, ContentsFlagsValue& flags) @@ -926,38 +782,47 @@ void Scene_BrushGetFlags_Component_Selected(scene::Graph& graph, ContentsFlagsVa if(!g_SelectedFaceInstances.empty()) { FaceInstance& faceInstance = g_SelectedFaceInstances.last(); - FaceShader_getFlags(faceInstance.getFace().getShader(), flags); + faceInstance.getFace().GetFlags(flags); } #else - FaceGetFlagsVisitor visitor(flags); - Scene_ForEachSelectedBrushFace(graph, visitor); + Scene_ForEachSelectedBrushFace(graph, FaceGetFlags(flags)); #endif } -class FaceGetShaderVisitor +class FaceGetShader { CopiedString& m_shader; mutable bool m_done; public: - FaceGetShaderVisitor(CopiedString& shader) + FaceGetShader(CopiedString& shader) : m_shader(shader), m_done(false) { } - void visit(Face& face) const + void operator()(Face& face) const { if(!m_done) { m_done = true; - m_shader = face.getShader().getShader(); + m_shader = face.GetShader(); } } }; void Scene_BrushGetShader_Selected(scene::Graph& graph, CopiedString& shader) { - FaceGetShaderVisitor visitor(shader); - Scene_ForEachSelectedBrush_ForEachFace(graph, visitor); +#if 1 + if(GlobalSelectionSystem().countSelected() != 0) + { + BrushInstance* brush = Instance_getBrush(GlobalSelectionSystem().ultimateSelected()); + if(brush != 0) + { + Brush_forEachFace(*brush, FaceGetShader(shader)); + } + } +#else + Scene_ForEachSelectedBrush_ForEachFace(graph, FaceGetShader(shader)); +#endif } void Scene_BrushGetShader_Component_Selected(scene::Graph& graph, CopiedString& shader) @@ -966,10 +831,10 @@ void Scene_BrushGetShader_Component_Selected(scene::Graph& graph, CopiedString& if(!g_SelectedFaceInstances.empty()) { FaceInstance& faceInstance = g_SelectedFaceInstances.last(); - shader = faceInstance.getFace().getShader().getShader(); + shader = faceInstance.getFace().GetShader(); } #else - FaceGetShaderVisitor visitor(shader); + FaceGetShader visitor(shader); Scene_ForEachSelectedBrushFace(graph, visitor); #endif } @@ -988,16 +853,16 @@ public: } }; -class filter_face_shader_substring : public FaceFilter +class filter_face_shader_prefix : public FaceFilter { - const char* m_shader; + const char* m_prefix; public: - filter_face_shader_substring(const char* shader) : m_shader(shader) + filter_face_shader_prefix(const char* prefix) : m_prefix(prefix) { } bool filter(const Face& face) const { - return shader_equal_n(face.GetShader(), m_shader, strlen(m_shader)); + return shader_equal_n(face.GetShader(), m_prefix, strlen(m_prefix)); } }; @@ -1029,16 +894,16 @@ public: -class FaceFilterAnyVisitor : public BrushVisitor +class FaceFilterAny { FaceFilter* m_filter; bool& m_filtered; public: - FaceFilterAnyVisitor(FaceFilter* filter, bool& filtered) : m_filter(filter), m_filtered(filtered) + FaceFilterAny(FaceFilter* filter, bool& filtered) : m_filter(filter), m_filtered(filtered) { m_filtered = false; } - void visit(Face& face) const + void operator()(Face& face) const { if(m_filter->filter(face)) { @@ -1057,21 +922,21 @@ public: bool filter(const Brush& brush) const { bool filtered; - brush.forEachFace(FaceFilterAnyVisitor(m_filter, filtered)); + Brush_forEachFace(brush, FaceFilterAny(m_filter, filtered)); return filtered; } }; -class FaceFilterAllVisitor : public BrushVisitor +class FaceFilterAll { FaceFilter* m_filter; bool& m_filtered; public: - FaceFilterAllVisitor(FaceFilter* filter, bool& filtered) : m_filter(filter), m_filtered(filtered) + FaceFilterAll(FaceFilter* filter, bool& filtered) : m_filter(filter), m_filtered(filtered) { m_filtered = true; } - void visit(Face& face) const + void operator()(Face& face) const { if(!m_filter->filter(face)) { @@ -1090,7 +955,7 @@ public: bool filter(const Brush& brush) const { bool filtered; - brush.forEachFace(FaceFilterAllVisitor(m_filter, filtered)); + Brush_forEachFace(brush, FaceFilterAll(m_filter, filtered)); return filtered; } }; @@ -1108,10 +973,13 @@ filter_brush_all_faces g_filter_brush_weapclip(&g_filter_face_weapclip); filter_face_shader g_filter_face_botclip("textures/common/botclip"); filter_brush_all_faces g_filter_brush_botclip(&g_filter_face_botclip); -filter_face_shader g_filter_face_caulk("textures/common/caulk"); +filter_face_shader_prefix g_filter_face_caulk("textures/common/caulk"); filter_brush_all_faces g_filter_brush_caulk(&g_filter_face_caulk); -filter_face_shader_substring g_filter_face_liquids("textures/liquids/"); +filter_face_shader_prefix g_filter_face_caulk_ja("textures/system/caulk"); +filter_brush_all_faces g_filter_brush_caulk_ja(&g_filter_face_caulk_ja); + +filter_face_shader_prefix g_filter_face_liquids("textures/liquids/"); filter_brush_any_face g_filter_brush_liquids(&g_filter_face_liquids); filter_face_shader g_filter_face_hint("textures/common/hint"); @@ -1120,6 +988,9 @@ filter_brush_any_face g_filter_brush_hint(&g_filter_face_hint); filter_face_shader g_filter_face_hint_q2("textures/hint"); filter_brush_any_face g_filter_brush_hint_q2(&g_filter_face_hint_q2); +filter_face_shader g_filter_face_hint_ja("textures/system/hint"); +filter_brush_any_face g_filter_brush_hint_ja(&g_filter_face_hint_ja); + filter_face_shader g_filter_face_areaportal("textures/common/areaportal"); filter_brush_all_faces g_filter_brush_areaportal(&g_filter_face_areaportal); @@ -1135,7 +1006,7 @@ filter_brush_all_faces g_filter_brush_lightgrid(&g_filter_face_lightgrid); filter_face_flags g_filter_face_translucent(QER_TRANS); filter_brush_all_faces g_filter_brush_translucent(&g_filter_face_translucent); -filter_face_contents g_filter_face_detail(CONTENTS_DETAIL); +filter_face_contents g_filter_face_detail(BRUSH_DETAIL_MASK); filter_brush_all_faces g_filter_brush_detail(&g_filter_face_detail); @@ -1146,9 +1017,13 @@ void BrushFilters_construct() add_brush_filter(g_filter_brush_weapclip, EXCLUDE_CLIP); add_brush_filter(g_filter_brush_botclip, EXCLUDE_BOTCLIP); add_brush_filter(g_filter_brush_caulk, EXCLUDE_CAULK); + add_brush_filter(g_filter_brush_caulk_ja, EXCLUDE_CAULK); + add_face_filter(g_filter_face_caulk, EXCLUDE_CAULK); + add_face_filter(g_filter_face_caulk_ja, EXCLUDE_CAULK); add_brush_filter(g_filter_brush_liquids, EXCLUDE_LIQUIDS); add_brush_filter(g_filter_brush_hint, EXCLUDE_HINTSSKIPS); add_brush_filter(g_filter_brush_hint_q2, EXCLUDE_HINTSSKIPS); + add_brush_filter(g_filter_brush_hint_ja, EXCLUDE_HINTSSKIPS); add_brush_filter(g_filter_brush_clusterportal, EXCLUDE_CLUSTERPORTALS); add_brush_filter(g_filter_brush_visportal, EXCLUDE_VISPORTALS); add_brush_filter(g_filter_brush_areaportal, EXCLUDE_AREAPORTALS); @@ -1499,188 +1374,6 @@ void Texdef_ToggleMoveLock() -void Face_getClosest(Face& face, SelectionTest& test, SelectionIntersection& bestIntersection, Face*& closestFace) -{ - SelectionIntersection intersection; - face.testSelect(test, intersection); - if(intersection.valid() - && SelectionIntersection_closer(intersection, bestIntersection)) - { - bestIntersection = intersection; - closestFace = &face; - } -} - - -class OccludeSelector : public Selector -{ - SelectionIntersection& m_bestIntersection; - bool& m_occluded; -public: - OccludeSelector(SelectionIntersection& bestIntersection, bool& occluded) : m_bestIntersection(bestIntersection), m_occluded(occluded) - { - m_occluded = false; - } - void pushSelectable(Selectable& selectable) - { - } - void popSelectable() - { - } - void addIntersection(const SelectionIntersection& intersection) - { - if(SelectionIntersection_closer(intersection, m_bestIntersection)) - { - m_bestIntersection = intersection; - m_occluded = true; - } - } -}; - -class BrushGetClosestFaceVisibleWalker : public scene::Graph::Walker -{ - SelectionTest& m_test; - Face*& m_closestFace; - mutable SelectionIntersection m_bestIntersection; -public: - BrushGetClosestFaceVisibleWalker(SelectionTest& test, Face*& closestFace) : m_test(test), m_closestFace(closestFace) - { - } - bool pre(const scene::Path& path, scene::Instance& instance) const - { - if(path.top().get().visible()) - { - BrushInstance* brush = Instance_getBrush(instance); - if(brush != 0) - { - m_test.BeginMesh(brush->localToWorld()); - - for(Brush::const_iterator i = brush->getBrush().begin(); i != brush->getBrush().end(); ++i) - { - Face_getClosest(*(*i), m_test, m_bestIntersection, m_closestFace); - } - } - else - { - SelectionTestable* selectionTestable = Instance_getSelectionTestable(instance); - if(selectionTestable) - { - bool occluded; - OccludeSelector selector(m_bestIntersection, occluded); - selectionTestable->testSelect(selector, m_test); - if(occluded) - { - m_closestFace = 0; - } - } - } - } - return true; - } -}; - -Face* Scene_BrushGetClosestFace(scene::Graph& graph, SelectionTest& test) -{ - Face* closestFace = 0; - graph.traverse(BrushGetClosestFaceVisibleWalker(test, closestFace)); - return closestFace; -} - -bool Scene_BrushGetClosestFaceTexture(scene::Graph& graph, SelectionTest& test, CopiedString& shader, TextureProjection& projection, ContentsFlagsValue& flags) -{ - Face* face = Scene_BrushGetClosestFace(graph, test); - if(face != 0) - { - shader = face->GetShader(); - FaceTexdef_getTexdef(face->getTexdef(), projection); - flags = face->getShader().m_flags; - return true; - } - return false; -} - -void Scene_BrushSetClosestFaceTexture(scene::Graph& graph, SelectionTest& test, const char* shader, const TextureProjection& projection, const ContentsFlagsValue& flags) -{ - Face* face = Scene_BrushGetClosestFace(graph, test); - if(face != 0) - { - face->SetShader(shader); - face->SetTexdef(projection); - face->SetFlags(flags); - } -} - - -class FaceTexture -{ -public: - TextureProjection m_projection; - ContentsFlagsValue m_flags; -}; - -FaceTexture g_faceTextureClipboard; - -void FaceTextureClipboard_setDefault() -{ - g_faceTextureClipboard.m_flags = ContentsFlagsValue(0, 0, 0, false); - TexDef_Construct_Default(g_faceTextureClipboard.m_projection); -} - -void TextureClipboard_textureSelected(const char* shader) -{ - FaceTextureClipboard_setDefault(); -} - -class TextureBrowser; -extern TextureBrowser g_TextureBrowser; -void TextureBrowser_SetSelectedShader(TextureBrowser& textureBrowser, const char* shader); -const char* TextureBrowser_GetSelectedShader(TextureBrowser& textureBrowser); - -void Scene_copyClosestFaceTexture(SelectionTest& test) -{ - CopiedString shader; - if(Scene_BrushGetClosestFaceTexture(GlobalSceneGraph(), test, shader, g_faceTextureClipboard.m_projection, g_faceTextureClipboard.m_flags)) - { - TextureBrowser_SetSelectedShader(g_TextureBrowser, shader.c_str()); - } -} - -void Scene_applyClosestFaceTexture(SelectionTest& test) -{ - UndoableCommand command("facePaintTexture"); - - Scene_BrushSetClosestFaceTexture(GlobalSceneGraph(), test, TextureBrowser_GetSelectedShader(g_TextureBrowser), g_faceTextureClipboard.m_projection, g_faceTextureClipboard.m_flags); - - SceneChangeNotify(); -} - - - -void SelectedFaces_copyTexture() -{ - if(!g_SelectedFaceInstances.empty()) - { - Face& face = g_SelectedFaceInstances.last().getFace(); - FaceTexdef_getTexdef(face.getTexdef(), g_faceTextureClipboard.m_projection); - g_faceTextureClipboard.m_flags = face.getShader().m_flags; - - TextureBrowser_SetSelectedShader(g_TextureBrowser, face.getShader().getShader()); - } -} - -void FaceInstance_pasteTexture(FaceInstance& faceInstance) -{ - faceInstance.getFace().SetTexdef(g_faceTextureClipboard.m_projection); - faceInstance.getFace().SetShader(TextureBrowser_GetSelectedShader(g_TextureBrowser)); - faceInstance.getFace().SetFlags(g_faceTextureClipboard.m_flags); - SceneChangeNotify(); -} - -void SelectedFaces_pasteTexture() -{ - UndoableCommand command("facePasteTexture"); - g_SelectedFaceInstances.foreach(FaceInstance_pasteTexture); -} void Brush_registerCommands() { @@ -1702,9 +1395,6 @@ void Brush_registerCommands() GlobalCommands_insert("SplitSelected", FreeCaller(), Accelerator(GDK_Return, (GdkModifierType)GDK_SHIFT_MASK)); GlobalCommands_insert("FlipClip", FreeCaller(), Accelerator(GDK_Return, (GdkModifierType)GDK_CONTROL_MASK)); - GlobalCommands_insert("FaceCopyTexture", FreeCaller()); - GlobalCommands_insert("FacePasteTexture", FreeCaller()); - GlobalCommands_insert("MakeDetail", FreeCaller(), Accelerator('M', (GdkModifierType)GDK_CONTROL_MASK)); GlobalCommands_insert("MakeStructural", FreeCaller(), Accelerator('S', (GdkModifierType)(GDK_SHIFT_MASK|GDK_CONTROL_MASK))); } @@ -1717,6 +1407,8 @@ void Brush_constructMenu(GtkMenu* menu) menu_separator (menu); { GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic (menu, "CSG"); + if (g_Layout_enableDetachableMenus.m_value) + menu_tearoff (menu_in_menu); create_menu_item_with_mnemonic(menu_in_menu, "Make _Hollow", "CSGHollow"); create_menu_item_with_mnemonic(menu_in_menu, "CSG _Subtract", "CSGSubtract"); create_menu_item_with_mnemonic(menu_in_menu, "CSG _Merge", "CSGMerge"); @@ -1724,6 +1416,8 @@ void Brush_constructMenu(GtkMenu* menu) menu_separator(menu); { GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic (menu, "Clipper"); + if (g_Layout_enableDetachableMenus.m_value) + menu_tearoff (menu_in_menu); create_menu_item_with_mnemonic(menu_in_menu, "Clip selection", "ClipSelected"); create_menu_item_with_mnemonic(menu_in_menu, "Split selection", "SplitSelected");