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_UVScaleTool 21 #define TrenchBroom_UVScaleTool 22 23 #include "Model/Hit.h" 24 #include "Renderer/VertexSpec.h" 25 #include "View/Tool.h" 26 #include "View/ToolController.h" 27 #include "View/ViewTypes.h" 28 29 namespace TrenchBroom { 30 namespace Assets { 31 class Texture; 32 } 33 34 namespace Model { 35 class PickResult; 36 } 37 38 namespace Renderer { 39 class RenderBatch; 40 class RenderContext; 41 } 42 43 namespace View { 44 class UVViewHelper; 45 46 class UVScaleTool : public ToolControllerBase<PickingPolicy, NoKeyPolicy, NoMousePolicy, MouseDragPolicy, RenderPolicy, NoDropPolicy>, public Tool { 47 private: 48 static const Model::Hit::HitType XHandleHit; 49 static const Model::Hit::HitType YHandleHit; 50 private: 51 typedef Renderer::VertexSpecs::P3::Vertex EdgeVertex; 52 53 MapDocumentWPtr m_document; 54 UVViewHelper& m_helper; 55 56 Vec2i m_handle; 57 Vec2b m_selector; 58 Vec2f m_lastHitPoint; // in non-scaled, non-translated texture coordinates 59 public: 60 UVScaleTool(MapDocumentWPtr document, UVViewHelper& helper); 61 private: 62 Tool* doGetTool(); 63 64 void doPick(const InputState& inputState, Model::PickResult& pickResult); 65 66 Vec2i getScaleHandle(const Model::Hit& xHit, const Model::Hit& yHit) const; 67 Vec2f getHitPoint(const Ray3& pickRay) const; 68 69 bool doStartMouseDrag(const InputState& inputState); 70 bool doMouseDrag(const InputState& inputState); 71 void doEndMouseDrag(const InputState& inputState); 72 void doCancelMouseDrag(); 73 74 Vec2f getScaledTranslatedHandlePos() const; 75 Vec2f getHandlePos() const; 76 Vec2f snap(const Vec2f& position) const; 77 78 void doRender(const InputState& inputState, Renderer::RenderContext& renderContext, Renderer::RenderBatch& renderBatch); 79 EdgeVertex::List getHandleVertices(const Model::PickResult& pickResult) const; 80 81 bool doCancel(); 82 }; 83 } 84 } 85 86 #endif /* defined(TrenchBroom_UVScaleTool) */ 87