Simple SFML GUI  0.2a
ColorProvider.hpp
1 #ifndef COLORPROVIDER_HPP
2 #define COLORPROVIDER_HPP
3 
4 #include <map>
5 #include <vector>
6 #include <memory>
7 #include <SFML/Graphics/Color.hpp>
8 #include "Enums.hpp"
9 
10 typedef std::pair<ColorId::Type, sf::Color&> ColorRef;
11 typedef std::vector<ColorRef> ColorRefVector;
12 
13 class Element;
14 
16 public:
17  friend Element;
18 
19  struct ColorInfo {
20  ColorInfo(const sf::Color& color = sf::Color::Transparent, bool enabled = false):
21  color(color),
22  enabled(enabled)
23  {}
24 
25  sf::Color color;
26  bool enabled = false;
27  };
28 
29  struct Internal {
30  std::map<StateId::Type, PairState> colorStateMap;
31  std::map<ColorId::Type, std::map<StateId::Type, ColorInfo>> colorInfoMap;
32  };
33 
34  ColorProvider(const ColorProvider& copy);
35  ColorProvider() = default;
36  ~ColorProvider() = default;
37  ColorProvider& operator=(const ColorProvider& colorProvider);
38  bool isStateRegistered(StateId::Type stateId) const;
39  bool registerState(StateId::Type stateId, const bool* state, bool inverted = false, bool overwrite = false);
40  inline bool registerState(StateId::Type stateId, const PairState& pair, bool overwrite = false) {
41  return registerState(stateId, pair.first, pair.second, overwrite);
42  }
43 
44  bool registerColor(ColorId::Type colorId, bool logError = true);
45  bool getRegisteredState(StateId::Type stateId, PairState& result);
46  bool setColorEnabled(ColorId::Type colorId, StateId::Type stateId, bool enabled);
47  bool getColor(ColorId::Type colorId, StateId::Type stateId, sf::Color& result) const;
48  bool setColor(ColorId::Type colorId, StateId::Type stateId, sf::Color newColor);
49  bool colorDeduce(const ColorRef& colorRef) const;
50  bool colorDeduce(const ColorRefVector& colorRefVector) const;
51  bool setColorFrom(const ColorProvider& provider);
52  bool setStateFrom(const ColorProvider& provider);
53 
54 private:
55  std::unique_ptr<Internal> internal;
56  static const bool alwaysTrue;
57 
58  void printColors() const;
59 };
60 
61 #endif // COLORPROVIDER_HPP
Definition: ColorProvider.hpp:29
Definition: ColorProvider.hpp:15
Definition: Element.hpp:22
Definition: ColorProvider.hpp:19