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_EntityBrowserView
21 #define TrenchBroom_EntityBrowserView
22 
23 #include "VecMath.h"
24 #include "Assets/EntityDefinitionManager.h"
25 #include "Renderer/VertexSpec.h"
26 #include "View/CellView.h"
27 #include "View/ViewTypes.h"
28 
29 namespace TrenchBroom {
30     class Logger;
31 
32     namespace Assets {
33         class EntityModelManager;
34         class PointEntityDefinition;
35     }
36 
37     namespace Renderer {
38         class FontDescriptor;
39         class TexturedIndexRangeRenderer;
40         class Transformation;
41     }
42 
43     namespace View {
44         class GLContextManager;
45 
46         typedef String EntityGroupData;
47 
48         class EntityCellData {
49         private:
50             typedef Renderer::TexturedIndexRangeRenderer EntityRenderer;
51         public:
52             Assets::PointEntityDefinition* entityDefinition;
53             EntityRenderer* modelRenderer;
54             Renderer::FontDescriptor fontDescriptor;
55             BBox3f bounds;
56 
57             EntityCellData(Assets::PointEntityDefinition* i_entityDefinition, EntityRenderer* i_modelRenderer, const Renderer::FontDescriptor& i_fontDescriptor, const BBox3f& i_bounds);
58         };
59 
60         class EntityBrowserView : public CellView<EntityCellData, EntityGroupData> {
61         private:
62             typedef Renderer::TexturedIndexRangeRenderer EntityRenderer;
63 
64             typedef Renderer::VertexSpecs::P2T2C4::Vertex TextVertex;
65             typedef std::map<Renderer::FontDescriptor, TextVertex::List> StringMap;
66 
67             Assets::EntityDefinitionManager& m_entityDefinitionManager;
68             Assets::EntityModelManager& m_entityModelManager;
69             Logger& m_logger;
70             Quatf m_rotation;
71 
72             bool m_group;
73             bool m_hideUnused;
74             Assets::EntityDefinition::SortOrder m_sortOrder;
75             String m_filterText;
76         public:
77             EntityBrowserView(wxWindow* parent,
78                               wxScrollBar* scrollBar,
79                               GLContextManager& contextManager,
80                               Assets::EntityDefinitionManager& entityDefinitionManager,
81                               Assets::EntityModelManager& entityModelManager,
82                               Logger& logger);
83             ~EntityBrowserView();
84         public:
85             void setSortOrder(Assets::EntityDefinition::SortOrder sortOrder);
86             void setGroup(bool group);
87             void setHideUnused(bool hideUnused);
88             void setFilterText(const String& filterText);
89         private:
90             void doInitLayout(Layout& layout);
91             void doReloadLayout(Layout& layout);
92 
93             bool dndEnabled();
94             void dndWillStart();
95             void dndDidEnd();
96             wxString dndData(const Layout::Group::Row::Cell& cell);
97 
98             void addEntityToLayout(Layout& layout, Assets::PointEntityDefinition* definition, const Renderer::FontDescriptor& font);
99 
100             void doClear();
101             void doRender(Layout& layout, float y, float height);
102             bool doShouldRenderFocusIndicator() const;
103 
104             void renderBounds(Layout& layout, float y, float height);
105 
106             class MeshFunc;
107             void renderModels(Layout& layout, float y, float height, Renderer::Transformation& transformation);
108 
109             void renderNames(Layout& layout, float y, float height, const Mat4x4f& projection);
110             void renderGroupTitleBackgrounds(Layout& layout, float y, float height);
111             void renderStrings(Layout& layout, float y, float height);
112             StringMap collectStringVertices(Layout& layout, float y, float height);
113 
114             Mat4x4f itemTransformation(const Layout::Group::Row::Cell& cell, float y, float height) const;
115 
116             wxString tooltip(const Layout::Group::Row::Cell& cell);
117         };
118     }
119 }
120 
121 #endif /* defined(TrenchBroom_EntityBrowserView) */
122