You.i Engine
YiHud.h
Go to the documentation of this file.
1 // © You i Labs Inc. 2000-2020. All rights reserved.
2 #ifndef _YI_HUD_H_
3 #define _YI_HUD_H_
4 
5 #include "utility/YiColor.h"
6 #include "utility/YiString.h"
7 
8 #include <glm/vec2.hpp>
9 
10 class CYIGeometryBatch;
11 
24 class CYIHud
25 {
26 public:
27  class Bar;
28  class SectionGroup;
29 
33  enum class BarAlignment
34  {
35  TopLeft,
36  TopCenter,
37  TopRight,
38  Center,
39  BottomLeft,
42  };
43 
49  enum class HudSection : uint8_t
50  {
51  ReservedGroupSection = 0,
52  DrawIndicator,
53  FrameMax,
54  FrameMinAvg,
55  Frames,
56  UpdateMax,
57  UpdateMinAvg,
58  DrawMax,
59  DrawMinAvg,
60  SwapMax,
61  SwapMinAvg,
62  ToolsMax,
63  ToolsMinAvg,
64  FPSMin,
65  FPSAvgMax,
66  Overdraw,
67  LegacyUpdate,
68  LegacyDraw,
69  LegacySwap,
70  LegacyFPS,
71  AtlasUsageRegular,
72  AtlasUsageSDF,
73  SystemMemory,
74  SystemMemoryTotal,
75  SystemMemoryPercentage,
76  ProcessMemory,
77  RSSMemory,
78  GPUMemory,
79  GPUMemoryTotal,
80  GPUMemoryPercentage,
81  SystemCPUUsagePercentage,
82  PerCPUUsageGraph,
83  ProcessCPUUsagePercentage,
84  GPUUsagePercentage,
85  LoadAverages,
86  EngineVersion,
87  EngineHash,
88  AppVersion,
89  EngineBuildConfiguration,
90  NetworkResponseRecordingWarning,
91  UserText,
92  UserSection // Must always be the last entry in the enum
93  };
94 
102  class Section
103  {
104  public:
105  friend class SectionGroup;
106 
107  Section(const CYIString &initialText, HudSection sectionType = HudSection::UserSection, const CYIColor &textColor = CYIColor::Named().White);
108  virtual ~Section();
109 
115  HudSection GetSectionType() const;
116 
122  float GetWidth() const;
123 
127  virtual void FrameUpdate() {}
128 
132  virtual void PeriodicUpdate() {}
133 
137  virtual void Draw(CYIGeometryBatch *pGeometryBatch, glm::vec2 topLeft) = 0;
138 
139  protected:
143  SectionGroup *GetParentGroup();
144 
148 
149  private:
150  Section();
151 
152  SectionGroup *m_pParentGroup;
153  };
154 
158  class SectionGroup : public Section
159  {
160  public:
161  friend class Bar;
162 
163  SectionGroup();
164 
168  void AddSection(std::unique_ptr<Section> pSection, bool enabled, float spacing = 9.0f);
169 
173  bool IsLogicallyDisabled() const;
174 
175  bool SetSectionEnabled(HudSection section, bool enabled);
176  bool IsSectionEnabled(HudSection section) const;
177 
178  virtual void FrameUpdate() override;
179  virtual void PeriodicUpdate() override;
180 
181  virtual void Draw(CYIGeometryBatch *pGeometryBatch, glm::vec2 topLeft) override;
182 
183  protected:
185 
186  private:
187  struct SectionInfo
188  {
189  bool enabled; // if the section is a section group, enabled is an 'or' of all contained sections
190  float spacing;
191  std::unique_ptr<Section> pSection;
192  };
193 
194 #ifndef DOXY
195  struct DrawData
196  {
197  struct Line
198  {
199  Line();
200 
201  float width;
202  glm::vec2 drawPosition;
203  };
204 
205  struct SectionToDraw
206  {
207  SectionToDraw(float xOffset, size_t lineIndex, Section *pSection);
208 
209  float xOffset;
210  size_t lineIndex;
211  Section *pSection;
212  };
213 
214  std::vector<Line> lines;
215  std::vector<SectionToDraw> sectionsToDraw;
216  };
217 #endif
218 
219  bool PopulateDrawData(float maximumLineWidth, DrawData *pDrawData) const;
220  void UpdateParentGroups();
221 
222  std::vector<SectionInfo> m_sections;
223  };
224 
230  class Bar final
231  {
232  public:
233  friend class CYIHud;
234 
235  Bar(CYIHud::BarAlignment alignment);
236  Bar(Bar &&) = default;
237  Bar &operator=(Bar &&) = default;
238 
242  void AddSection(std::unique_ptr<Section> pSection, bool enabled, float spacing = 9.0f);
243 
247  void SetSectionEnabled(HudSection section, bool enabled);
248 
252  bool IsSectionEnabled(HudSection section) const;
253 
257  void FrameUpdate();
258 
262  void PeriodicUpdate();
263 
267  float Draw(CYIGeometryBatch *pGeometryBatch, glm::vec2 screenSize, float verticalOffset);
268 
272  CYIHud::BarAlignment GetAlignment() const;
273 
274  private:
275  struct SectionInfo
276  {
277  bool enabled = false;
278  float spacing = 9.0f;
279  std::unique_ptr<Section> pSection;
280  };
281 
282  void UpdateParentGroups();
283 
284  CYIHud::BarAlignment m_alignment;
285  SectionGroup::DrawData m_drawData;
286  SectionGroup m_sections;
287  };
288 
289  CYIHud();
290 
300  Bar *AddBar(BarAlignment alignment);
301 
305  void SetSectionEnabled(HudSection section, bool enabled);
306 
310  bool IsSectionEnabled(HudSection section) const;
311 
315  std::vector<const Bar *> GetBars() const;
316  std::vector<Bar *> GetBars();
317 
321  Bar *GetMainBar();
322 
326  bool Update();
327 
331  void Draw();
332 
336  static void SetUserText(const CYIString &text);
337  static const CYIString &GetUserText();
338 
339 private:
340  void FrameUpdate();
341  void PeriodicUpdate();
342 
343  std::vector<Bar> m_bars;
344  uint64_t m_lastHudRenderTimeuS;
345  static CYIString m_userText;
346 };
347 
352 #endif
std::vector< const Bar * > GetBars() const
void Draw()
bool IsSectionEnabled(HudSection section) const
bool Update()
static const CYIString & GetUserText()
Definition: YiHud.h:230
Container class for Unicode strings. Conceptually, a CYIString object is a sequence of Unicode charac...
Definition: YiString.h:36
HudSection m_sectionType
Definition: YiHud.h:147
Allows drawing of simple 2D geometry in batch.
Definition: YiGeometryBatch.h:30
Bar * AddBar(BarAlignment alignment)
static const CYINamedColors & Named()
virtual void PeriodicUpdate()
Definition: YiHud.h:132
Bar * GetMainBar()
HudSection
Definition: YiHud.h:49
Definition: YiHud.h:158
Definition: YiHud.h:102
bool m_logicallyDisabled
Definition: YiHud.h:184
BarAlignment
Definition: YiHud.h:33
static void SetUserText(const CYIString &text)
virtual void FrameUpdate()
Definition: YiHud.h:127
CYIColor m_textColor
Definition: YiHud.h:146
A class used to display information on top of the rendered scenes.
Definition: YiHud.h:24
void SetSectionEnabled(HudSection section, bool enabled)
A class used to represent a color value.
Definition: YiColor.h:31
CYIString m_text
Definition: YiHud.h:145