1 /* 2 Copyright (C) 2010-2014 Kristian Duske 3 4 This file is part of TrenchBroom. 5 6 TrenchBroom is free software: you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 TrenchBroom is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with TrenchBroom. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef TrenchBroom_ClipToolController 21 #define TrenchBroom_ClipToolController 22 23 #include "TrenchBroom.h" 24 #include "VecMath.h" 25 #include "Renderer/RenderContext.h" 26 #include "View/ClipTool.h" 27 #include "View/InputState.h" 28 #include "View/ToolController.h" 29 30 namespace TrenchBroom { 31 namespace Model { 32 class BrushFace; 33 class PickResult; 34 } 35 36 namespace Renderer { 37 class RenderBatch; 38 class RenderContext; 39 } 40 41 namespace View { 42 class ClipTool; 43 class Grid; 44 class InputState; 45 class Tool; 46 47 class ClipToolController : public ToolControllerGroup { 48 protected: 49 class Callback { 50 protected: 51 ClipTool* m_tool; 52 public: 53 Callback(ClipTool* tool); 54 virtual ~Callback(); 55 ClipTool* tool() const; 56 57 bool addClipPoint(const InputState& inputState, Vec3& position); 58 bool setClipFace(const InputState& inputState); 59 60 virtual DragRestricter* createDragRestricter(const InputState& inputState, const Vec3& initialPoint) const = 0; 61 virtual DragSnapper* createDragSnapper(const InputState& inputState) const = 0; 62 virtual Vec3::List getHelpVectors(const InputState& inputState) const = 0; 63 64 void renderFeedback(const InputState& inputState, Renderer::RenderContext& renderContext, Renderer::RenderBatch& renderBatch); 65 private: 66 virtual bool doGetNewClipPointPosition(const InputState& inputState, Vec3& position) const = 0; 67 }; 68 69 class PartBase { 70 protected: 71 Callback* m_callback; 72 PartBase(Callback* callback); 73 public: 74 virtual ~PartBase(); 75 }; 76 77 class AddClipPointPart : public ToolControllerBase<NoPickingPolicy, NoKeyPolicy, MousePolicy, RestrictedDragPolicy, RenderPolicy, NoDropPolicy>, protected PartBase { 78 private: 79 bool m_secondPointSet; 80 public: 81 AddClipPointPart(Callback* callback); 82 private: 83 Tool* doGetTool(); 84 bool doMouseClick(const InputState& inputState); 85 bool doMouseDoubleClick(const InputState& inputState); 86 DragInfo doStartDrag(const InputState& inputState); 87 DragResult doDrag(const InputState& inputState, const Vec3& lastPoint, const Vec3& curPoint); 88 void doEndDrag(const InputState& inputState); 89 void doCancelDrag(); 90 void doRender(const InputState& inputState, Renderer::RenderContext& renderContext, Renderer::RenderBatch& renderBatch); 91 bool doCancel(); 92 }; 93 94 class MoveClipPointPart : public ToolControllerBase<NoPickingPolicy, NoKeyPolicy, NoMousePolicy, RestrictedDragPolicy, NoRenderPolicy, NoDropPolicy>, protected PartBase { 95 public: 96 MoveClipPointPart(Callback* callback); 97 private: 98 Tool* doGetTool(); 99 DragInfo doStartDrag(const InputState& inputState); 100 DragResult doDrag(const InputState& inputState, const Vec3& lastPoint, const Vec3& curPoint); 101 void doEndDrag(const InputState& inputState); 102 void doCancelDrag(); 103 bool doCancel(); 104 }; 105 protected: 106 ClipTool* m_tool; 107 protected: 108 ClipToolController(ClipTool* tool); 109 virtual ~ClipToolController(); 110 private: 111 Tool* doGetTool(); 112 113 void doPick(const InputState& inputState, Model::PickResult& pickResult); 114 115 void doSetRenderOptions(const InputState& inputState, Renderer::RenderContext& renderContext) const; 116 void doRender(const InputState& inputState, Renderer::RenderContext& renderContext, Renderer::RenderBatch& renderBatch); 117 118 bool doCancel(); 119 }; 120 121 class ClipToolController2D : public ClipToolController { 122 private: 123 class Callback2D; 124 public: 125 ClipToolController2D(ClipTool* tool); 126 }; 127 128 class ClipToolController3D : public ClipToolController { 129 private: 130 static Vec3::List selectHelpVectors(Model::BrushFace* face, const Vec3& hitPoint); 131 static Model::BrushFaceList selectIncidentFaces(Model::BrushFace* face, const Vec3& hitPoint); 132 private: 133 class Callback3D; 134 public: 135 ClipToolController3D(ClipTool* tool); 136 }; 137 } 138 } 139 140 #endif /* defined(TrenchBroom_ClipToolController) */ 141