cesium-native  0.41.0
CreditSystem.h
1 #pragma once
2 
3 #include "Library.h"
4 
5 #include <string>
6 #include <unordered_map>
7 #include <utility>
8 #include <vector>
9 
10 namespace CesiumUtility {
11 
17 struct CESIUMUTILITY_API Credit {
18 public:
22  bool operator==(const Credit& rhs) const noexcept {
23  return this->id == rhs.id;
24  }
25 
26 private:
27  size_t id;
28 
29  Credit(size_t id_) noexcept { id = id_; }
30 
31  friend class CreditSystem;
32 };
33 
39 class CESIUMUTILITY_API CreditSystem final {
40 public:
47  Credit createCredit(std::string&& html, bool showOnScreen = false);
48 
55  Credit createCredit(const std::string& html, bool showOnScreen = false);
56 
60  bool shouldBeShownOnScreen(Credit credit) const noexcept;
61 
65  void setShowOnScreen(Credit credit, bool showOnScreen) noexcept;
66 
70  const std::string& getHtml(Credit credit) const noexcept;
71 
75  void addCreditToFrame(Credit credit);
76 
81  void startNextFrame() noexcept;
82 
86  const std::vector<Credit>& getCreditsToShowThisFrame() noexcept;
87 
92  const std::vector<Credit>&
93  getCreditsToNoLongerShowThisFrame() const noexcept {
94  return _creditsToNoLongerShowThisFrame;
95  }
96 
97 private:
98  const std::string INVALID_CREDIT_MESSAGE =
99  "Error: Invalid Credit, cannot get HTML string.";
100 
101  struct HtmlAndLastFrameNumber {
102  std::string html;
103  bool showOnScreen;
104  int32_t lastFrameNumber;
105  int count;
106  };
107 
108  std::vector<HtmlAndLastFrameNumber> _credits;
109 
110  int32_t _currentFrameNumber = 0;
111  std::vector<Credit> _creditsToShowThisFrame;
112  std::vector<Credit> _creditsToNoLongerShowThisFrame;
113 };
114 } // namespace CesiumUtility
Creates and manages Credit objects. Avoids repetitions and tracks which credits should be shown and w...
Definition: CreditSystem.h:39
bool shouldBeShownOnScreen(Credit credit) const noexcept
Gets whether or not the credit should be shown on screen.
void startNextFrame() noexcept
Notifies this CreditSystem to start tracking the credits to show for the next frame.
Credit createCredit(std::string &&html, bool showOnScreen=false)
Inserts a credit string.
void addCreditToFrame(Credit credit)
Adds the Credit to the set of credits to show this frame.
void setShowOnScreen(Credit credit, bool showOnScreen) noexcept
Sets whether or not the credit should be shown on screen.
const std::string & getHtml(Credit credit) const noexcept
Get the HTML string for this credit.
Credit createCredit(const std::string &html, bool showOnScreen=false)
Inserts a credit string.
Utility classes for Cesium.
Represents an HTML string that should be shown on screen to attribute third parties for used data,...
Definition: CreditSystem.h:17
bool operator==(const Credit &rhs) const noexcept
Returns true if two credit objects have the same ID.
Definition: CreditSystem.h:22