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 "MoveTexturesCommand.h" 21 22 #include "Model/BrushFace.h" 23 #include "View/MapDocumentCommandFacade.h" 24 25 namespace TrenchBroom { 26 namespace View { 27 const Command::CommandType MoveTexturesCommand::Type = Command::freeType(); 28 move(const Vec3f & cameraUp,const Vec3f & cameraRight,const Vec2f & delta)29 MoveTexturesCommand::Ptr MoveTexturesCommand::move(const Vec3f& cameraUp, const Vec3f& cameraRight, const Vec2f& delta) { 30 return Ptr(new MoveTexturesCommand(cameraUp, cameraRight, delta)); 31 } 32 MoveTexturesCommand(const Vec3f & cameraUp,const Vec3f & cameraRight,const Vec2f & delta)33 MoveTexturesCommand::MoveTexturesCommand(const Vec3f& cameraUp, const Vec3f& cameraRight, const Vec2f& delta) : 34 DocumentCommand(Type, "Move Textures"), 35 m_cameraUp(cameraUp), 36 m_cameraRight(cameraRight), 37 m_delta(delta) {} 38 doPerformDo(MapDocumentCommandFacade * document)39 bool MoveTexturesCommand::doPerformDo(MapDocumentCommandFacade* document) { 40 moveTextures(document, m_delta); 41 return true; 42 } 43 doPerformUndo(MapDocumentCommandFacade * document)44 bool MoveTexturesCommand::doPerformUndo(MapDocumentCommandFacade* document) { 45 moveTextures(document, -m_delta); 46 return true; 47 } 48 moveTextures(MapDocumentCommandFacade * document,const Vec2f & delta) const49 void MoveTexturesCommand::moveTextures(MapDocumentCommandFacade* document, const Vec2f& delta) const { 50 document->performMoveTextures(m_cameraUp, m_cameraRight, delta); 51 } 52 doIsRepeatable(MapDocumentCommandFacade * document) const53 bool MoveTexturesCommand::doIsRepeatable(MapDocumentCommandFacade* document) const { 54 return true; 55 } 56 doRepeat(MapDocumentCommandFacade * document) const57 UndoableCommand::Ptr MoveTexturesCommand::doRepeat(MapDocumentCommandFacade* document) const { 58 return UndoableCommand::Ptr(new MoveTexturesCommand(*this)); 59 } 60 doCollateWith(UndoableCommand::Ptr command)61 bool MoveTexturesCommand::doCollateWith(UndoableCommand::Ptr command) { 62 const MoveTexturesCommand* other = static_cast<MoveTexturesCommand*>(command.get()); 63 64 if (other->m_cameraUp != m_cameraUp || 65 other->m_cameraRight != m_cameraRight) 66 return false; 67 68 m_delta += other->m_delta; 69 return true; 70 } 71 } 72 } 73