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_UVView
21 #define TrenchBroom_UVView
22 
23 #include "TrenchBroom.h"
24 #include "VecMath.h"
25 #include "Model/Hit.h"
26 #include "Model/PickResult.h"
27 #include "Model/ModelTypes.h"
28 #include "Renderer/OrthographicCamera.h"
29 #include "View/RenderView.h"
30 #include "View/ToolBox.h"
31 #include "View/ToolBoxConnector.h"
32 #include "View/UVViewHelper.h"
33 #include "View/ViewTypes.h"
34 
35 class wxWindow;
36 
37 namespace TrenchBroom {
38     namespace IO {
39         class Path;
40     }
41 
42     namespace Renderer {
43         class ActiveShader;
44         class RenderBatch;
45         class RenderContext;
46     }
47 
48     namespace View {
49         class Selection;
50         class UVRotateTool;
51         class UVOriginTool;
52         class UVScaleTool;
53         class UVShearTool;
54         class UVOffsetTool;
55         class UVCameraTool;
56 
57         /**
58          A view which allows the user to manipulate the texture projection interactively with the mouse. The user can
59          change texture offsets, scaling factors and rotation. If supported by the map format, the user can manipulate
60          the texture axes as well.
61          */
62         class UVView : public RenderView, public ToolBoxConnector {
63         public:
64             static const Model::Hit::HitType FaceHit;
65         private:
66             MapDocumentWPtr m_document;
67 
68             Renderer::OrthographicCamera m_camera;
69             UVViewHelper m_helper;
70 
71             ToolBox m_toolBox;
72         public:
73             UVView(wxWindow* parent, MapDocumentWPtr document, GLContextManager& contextManager);
74             ~UVView();
75 
76             void setSubDivisions(const Vec2i& subDivisions);
77         private:
78             void createTools();
79 
80             void bindObservers();
81             void unbindObservers();
82 
83             void selectionDidChange(const Selection& selection);
84             void nodesDidChange(const Model::NodeList& nodes);
85             void brushFacesDidChange(const Model::BrushFaceList& faces);
86             void gridDidChange();
87             void cameraDidChange(const Renderer::Camera* camera);
88             void preferenceDidChange(const IO::Path& path);
89 
90             void doUpdateViewport(int x, int y, int width, int height);
91             void doRender();
92             bool doShouldRenderFocusIndicator() const;
93 
94             void setupGL(Renderer::RenderContext& renderContext);
95 
96             class RenderTexture;
97             void renderTexture(Renderer::RenderContext& renderContext, Renderer::RenderBatch& renderBatch);
98 
99             void renderFace(Renderer::RenderContext& renderContext, Renderer::RenderBatch& renderBatch);
100             void renderTextureAxes(Renderer::RenderContext& renderContext, Renderer::RenderBatch& renderBatch);
101             void renderToolBox(Renderer::RenderContext& renderContext, Renderer::RenderBatch& renderBatch);
102         private:
103             PickRequest doGetPickRequest(int x, int y) const;
104             Model::PickResult doPick(const Ray3& pickRay) const;
105         };
106     }
107 }
108 
109 #endif /* defined(TrenchBroom_UVView) */
110