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_TextureBrowserView 21 #define TrenchBroom_TextureBrowserView 22 23 #include "StringUtils.h" 24 #include "Assets/TextureManager.h" 25 #include "Renderer/FontDescriptor.h" 26 #include "Renderer/Vbo.h" 27 #include "Renderer/Vertex.h" 28 #include "Renderer/VertexSpec.h" 29 #include "View/CellView.h" 30 31 #include <map> 32 33 class wxScrollBar; 34 35 namespace TrenchBroom { 36 namespace Assets { 37 class Texture; 38 class TextureCollection; 39 } 40 41 namespace View { 42 class GLContextManager; 43 typedef String TextureGroupData; 44 45 class TextureCellData { 46 public: 47 Assets::Texture* texture; 48 Renderer::FontDescriptor fontDescriptor; 49 50 TextureCellData(Assets::Texture* i_texture, const Renderer::FontDescriptor& i_fontDescriptor); 51 }; 52 53 class TextureBrowserView : public CellView<TextureCellData, TextureGroupData> { 54 private: 55 typedef Renderer::VertexSpecs::P2T2C4::Vertex TextVertex; 56 typedef std::map<Renderer::FontDescriptor, TextVertex::List> StringMap; 57 58 Assets::TextureManager& m_textureManager; 59 60 bool m_group; 61 bool m_hideUnused; 62 Assets::TextureManager::SortOrder m_sortOrder; 63 String m_filterText; 64 65 Assets::Texture* m_selectedTexture; 66 public: 67 TextureBrowserView(wxWindow* parent, 68 wxScrollBar* scrollBar, 69 GLContextManager& contextManager, 70 Assets::TextureManager& textureManager); 71 ~TextureBrowserView(); 72 73 void setSortOrder(Assets::TextureManager::SortOrder sortOrder); 74 void setGroup(bool group); 75 void setHideUnused(bool hideUnused); 76 void setFilterText(const String& filterText); 77 78 Assets::Texture* selectedTexture() const; 79 void setSelectedTexture(Assets::Texture* selectedTexture); 80 private: 81 void doInitLayout(Layout& layout); 82 void doReloadLayout(Layout& layout); 83 void addTextureToLayout(Layout& layout, Assets::Texture* texture, const Renderer::FontDescriptor& font); 84 85 void doClear(); 86 void doRender(Layout& layout, float y, float height); 87 bool doShouldRenderFocusIndicator() const; 88 89 void renderBounds(Layout& layout, float y, float height); 90 const Color& textureColor(const Assets::Texture& texture) const; 91 void renderTextures(Layout& layout, float y, float height); 92 void renderNames(Layout& layout, float y, float height); 93 void renderGroupTitleBackgrounds(Layout& layout, float y, float height); 94 void renderStrings(Layout& layout, float y, float height); 95 StringMap collectStringVertices(Layout& layout, float y, float height); 96 97 void doLeftClick(Layout& layout, float x, float y); 98 wxString tooltip(const Layout::Group::Row::Cell& cell); 99 }; 100 } 101 } 102 103 #endif /* defined(TrenchBroom_TextureBrowserView) */ 104