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 #include "MoveObjectsToolController.h" 21 22 #include "Model/Brush.h" 23 #include "Model/Entity.h" 24 #include "Model/Group.h" 25 #include "Model/HitAdapter.h" 26 #include "Model/HitQuery.h" 27 #include "Model/Node.h" 28 #include "Renderer/RenderContext.h" 29 #include "View/MoveObjectsTool.h" 30 31 #include <cassert> 32 33 namespace TrenchBroom { 34 namespace View { MoveObjectsToolController(MoveObjectsTool * tool)35 MoveObjectsToolController::MoveObjectsToolController(MoveObjectsTool* tool) : 36 MoveToolController(tool->grid()), 37 m_tool(tool) { 38 assert(m_tool != NULL); 39 } 40 ~MoveObjectsToolController()41 MoveObjectsToolController::~MoveObjectsToolController() {} 42 doGetTool()43 Tool* MoveObjectsToolController::doGetTool() { 44 return m_tool; 45 } 46 doStartMove(const InputState & inputState)47 MoveObjectsToolController::MoveInfo MoveObjectsToolController::doStartMove(const InputState& inputState) { 48 if (!inputState.modifierKeysPressed(ModifierKeys::MKNone) && 49 !inputState.modifierKeysPressed(ModifierKeys::MKAlt) && 50 !inputState.modifierKeysPressed(ModifierKeys::MKCtrlCmd) && 51 !inputState.modifierKeysPressed(ModifierKeys::MKCtrlCmd | ModifierKeys::MKAlt)) 52 return MoveInfo(); 53 54 const Model::PickResult& pickResult = inputState.pickResult(); 55 const Model::Hit& hit = pickResult.query().pickable().type(Model::Group::GroupHit | Model::Entity::EntityHit | Model::Brush::BrushHit).selected().first(); 56 if (!hit.isMatch()) 57 return MoveInfo(); 58 59 if (!m_tool->startMove(inputState)) 60 return MoveInfo(); 61 62 return MoveInfo(hit.hitPoint()); 63 } 64 doMove(const InputState & inputState,const Vec3 & lastPoint,const Vec3 & curPoint)65 RestrictedDragPolicy::DragResult MoveObjectsToolController::doMove(const InputState& inputState, const Vec3& lastPoint, const Vec3& curPoint) { 66 switch (m_tool->move(inputState, curPoint - lastPoint)) { 67 case MoveObjectsTool::MR_Continue: 68 return DR_Continue; 69 case MoveObjectsTool::MR_Deny: 70 return DR_Deny; 71 case MoveObjectsTool::MR_Cancel: 72 return DR_Cancel; 73 switchDefault(); 74 } 75 } 76 doEndMove(const InputState & inputState)77 void MoveObjectsToolController::doEndMove(const InputState& inputState) { 78 m_tool->endMove(inputState); 79 } 80 doCancelMove()81 void MoveObjectsToolController::doCancelMove() { 82 m_tool->cancelMove(); 83 } 84 doSetRenderOptions(const InputState & inputState,Renderer::RenderContext & renderContext) const85 void MoveObjectsToolController::doSetRenderOptions(const InputState& inputState, Renderer::RenderContext& renderContext) const { 86 if (thisToolDragging()) 87 renderContext.setForceShowSelectionGuide(); 88 } 89 doCancel()90 bool MoveObjectsToolController::doCancel() { 91 return false; 92 } 93 } 94 } 95