Overte C++ Documentation
HighlightStage.h
1 //
2 // HighlightStage.h
3 
4 // Created by Olivier Prat on 07/07/2017.
5 // Copyright 2017 High Fidelity, Inc.
6 //
7 // Distributed under the Apache License, Version 2.0.
8 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
9 //
10 
11 #ifndef hifi_render_utils_HighlightStage_h
12 #define hifi_render_utils_HighlightStage_h
13 
14 #include "Stage.h"
15 #include "Engine.h"
16 #include "IndexedContainer.h"
17 #include "HighlightStyle.h"
18 
19 namespace render {
20 
21  // Highlight stage to set up HighlightStyle-related effects
22  class HighlightStage : public Stage {
23  public:
24 
25  class Highlight {
26  public:
27 
28  Highlight(const std::string& selectionName, const HighlightStyle& style) : _selectionName{ selectionName }, _style{ style } { }
29 
30  std::string _selectionName;
31  HighlightStyle _style;
32 
33  };
34 
35  static const std::string& getName() { return _name; }
36 
37  using Index = render::indexed_container::Index;
38  static const Index INVALID_INDEX;
39  using HighlightIdList = render::indexed_container::Indices;
40 
41  static bool isIndexInvalid(Index index) { return index == INVALID_INDEX; }
42 
43  bool checkHighlightId(Index index) const { return _highlights.checkIndex(index); }
44 
45  const Highlight& getHighlight(Index index) const { return _highlights.get(index); }
46  Highlight& editHighlight(Index index) { return _highlights.edit(index); }
47 
48  Index addHighlight(const std::string& selectionName, const HighlightStyle& style = HighlightStyle());
49  Index getHighlightIdBySelection(const std::string& selectionName) const;
50  void removeHighlight(Index index);
51 
52  HighlightIdList::iterator begin() { return _activeHighlightIds.begin(); }
53  HighlightIdList::iterator end() { return _activeHighlightIds.end(); }
54  const HighlightIdList& getActiveHighlightIds() const { return _activeHighlightIds; }
55 
56  private:
57 
58  using Highlights = render::indexed_container::IndexedVector<Highlight>;
59 
60  static std::string _name;
61 
62  Highlights _highlights;
63  HighlightIdList _activeHighlightIds;
64  };
65  using HighlightStagePointer = std::shared_ptr<HighlightStage>;
66 
67  class HighlightStageConfig : public render::Job::Config {
68  Q_OBJECT
69  Q_PROPERTY(QString selectionName READ getSelectionName WRITE setSelectionName NOTIFY dirty)
70  Q_PROPERTY(bool isOutlineSmooth READ isOutlineSmooth WRITE setOutlineSmooth NOTIFY dirty)
71  Q_PROPERTY(float colorR READ getColorRed WRITE setColorRed NOTIFY dirty)
72  Q_PROPERTY(float colorG READ getColorGreen WRITE setColorGreen NOTIFY dirty)
73  Q_PROPERTY(float colorB READ getColorBlue WRITE setColorBlue NOTIFY dirty)
74  Q_PROPERTY(float outlineWidth READ getOutlineWidth WRITE setOutlineWidth NOTIFY dirty)
75  Q_PROPERTY(float outlineIntensity READ getOutlineIntensity WRITE setOutlineIntensity NOTIFY dirty)
76  Q_PROPERTY(float unoccludedFillOpacity READ getUnoccludedFillOpacity WRITE setUnoccludedFillOpacity NOTIFY dirty)
77  Q_PROPERTY(float occludedFillOpacity READ getOccludedFillOpacity WRITE setOccludedFillOpacity NOTIFY dirty)
78 
79  public:
80 
81  using SelectionStyles = std::map<std::string, HighlightStyle>;
82 
83  QString getSelectionName() const { return QString(_selectionName.c_str()); }
84  void setSelectionName(const QString& name);
85 
86  bool isOutlineSmooth() const { return getStyle()._isOutlineSmooth; }
87  void setOutlineSmooth(bool isSmooth);
88 
89  float getColorRed() const { return getStyle()._outlineUnoccluded.color.r; }
90  void setColorRed(float value);
91 
92  float getColorGreen() const { return getStyle()._outlineUnoccluded.color.g; }
93  void setColorGreen(float value);
94 
95  float getColorBlue() const { return getStyle()._outlineUnoccluded.color.b; }
96  void setColorBlue(float value);
97 
98  float getOutlineWidth() const { return getStyle()._outlineWidth; }
99  void setOutlineWidth(float value);
100 
101  float getOutlineIntensity() const { return getStyle()._outlineUnoccluded.alpha; }
102  void setOutlineIntensity(float value);
103 
104  float getUnoccludedFillOpacity() const { return getStyle()._fillUnoccluded.alpha; }
105  void setUnoccludedFillOpacity(float value);
106 
107  float getOccludedFillOpacity() const { return getStyle()._fillOccluded.alpha; }
108  void setOccludedFillOpacity(float value);
109 
110  std::string _selectionName { "contextOverlayHighlightList" };
111  mutable SelectionStyles _styles;
112 
113  const HighlightStyle& getStyle() const;
114  HighlightStyle& editStyle();
115 
116  signals:
117  void dirty();
118  };
119 
120  class HighlightStageSetup {
121  public:
122  using Config = HighlightStageConfig;
123  using JobModel = render::Job::Model<HighlightStageSetup, Config>;
124 
125  HighlightStageSetup();
126 
127  void configure(const Config& config);
128  void run(const RenderContextPointer& renderContext);
129 
130  protected:
131 
132  HighlightStageConfig::SelectionStyles _styles;
133  };
134 
135 }
136 #endif // hifi_render_utils_HighlightStage_h