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_GroupRenderer
21 #define TrenchBroom_GroupRenderer
22 
23 #include "AttrString.h"
24 #include "Color.h"
25 #include "Model/ModelTypes.h"
26 #include "Renderer/EdgeRenderer.h"
27 
28 namespace TrenchBroom {
29     namespace Model {
30         class EditorContext;
31     }
32 
33     namespace Renderer {
34         class RenderBatch;
35         class RenderContext;
36 
37         class GroupRenderer {
38         private:
39             class GroupNameAnchor;
40 
41             const Model::EditorContext& m_editorContext;
42             Model::GroupList m_groups;
43 
44             DirectEdgeRenderer m_boundsRenderer;
45             bool m_boundsValid;
46 
47             bool m_showOverlays;
48             Color m_overlayTextColor;
49             Color m_overlayBackgroundColor;
50             bool m_showOccludedOverlays;
51             bool m_overrideBoundsColor;
52             Color m_boundsColor;
53             bool m_showOccludedBounds;
54             Color m_occludedBoundsColor;
55         public:
56             GroupRenderer(const Model::EditorContext& editorContext);
57 
58             void setGroups(const Model::GroupList& groups);
59             void invalidate();
60             void clear();
61 
62             template <typename Iter>
addGroups(Iter cur,const Iter end)63             void addGroups(Iter cur, const Iter end) {
64                 while (cur != end) {
65                     addGroup(*cur);
66                     ++cur;
67                 }
68             }
69             template <typename Iter>
updateGroups(Iter cur,const Iter end)70             void updateGroups(Iter cur, const Iter end) {
71                 while (cur != end) {
72                     updateGroup(*cur);
73                     ++cur;
74                 }
75             }
76 
77             template <typename Iter>
removeGroups(Iter cur,const Iter end)78             void removeGroups(Iter cur, const Iter end) {
79                 while (cur != end) {
80                     removeGroup(*cur);
81                     ++cur;
82                 }
83             }
84 
85             void setShowOverlays(bool showOverlays);
86             void setOverlayTextColor(const Color& overlayTextColor);
87             void setOverlayBackgroundColor(const Color& overlayBackgroundColor);
88             void setShowOccludedOverlays(bool showOccludedOverlays);
89 
90             void setOverrideBoundsColor(bool overrideBoundsColor);
91             void setBoundsColor(const Color& boundsColor);
92 
93             void setShowOccludedBounds(bool showOccludedBounds);
94             void setOccludedBoundsColor(const Color& occludedBoundsColor);
95         public: // rendering
96             void render(RenderContext& renderContext, RenderBatch& renderBatch);
97         private:
98             void renderBounds(RenderContext& renderContext, RenderBatch& renderBatch);
99             void renderNames(RenderContext& renderContext, RenderBatch& renderBatch);
100 
101             struct BuildColoredBoundsVertices;
102             struct BuildBoundsVertices;
103 
104             void invalidateBounds();
105             void validateBounds();
106 
107             AttrString groupString(const Model::Group* group) const;
108             const Color& boundsColor(const Model::Group* group) const;
109         };
110     }
111 }
112 
113 #endif /* defined(TrenchBroom_GroupRenderer) */
114