Simple SFML GUI  0.2a
Checkbox.hpp
1 #ifndef CHECKBOX_HPP
2 #define CHECKBOX_HPP
3 
4 #include "Enums.hpp"
5 #include "Pressable.hpp"
6 #include "HaveEnabled.hpp"
7 #include "HaveOutline.hpp"
8 #include "HaveBackground.hpp"
9 
10 #include "CBAssigner.hpp"
11 #include "CBAssignerNeg.hpp"
12 
13 namespace ActionType {
14  namespace Checkbox {
15  namespace State {
16  const char* const changed = "checkboxStateChanged";
17  const char* const checked = "checkboxStateChecked";
18  const char* const unchecked = "checkboxStateUnchecked";
19  const char* const partly = "checkboxStatePartly";
20  }
21  }
22 }
23 
24 class Checkbox :
25  public Pressable<Checkbox&>,
26  public HaveEnabled,
27  public HaveOutline,
28  public HaveBackground {
29 public:
30  Checkbox(bool* var = nullptr);
31  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) override;
32  virtual bool update(sf::Vector2f mp, bool pressLeft, bool pressRight, bool aboveHover) override;
33  virtual void updateArea() override;
34 
35  void assign(bool* var);
36  void assignNegative(bool* var);
37  CBState getState() const;
38  void setState(CBState value);
39 
40  void setSymbol(CBState state, const sf::VertexArray& value);
41  void setSymbol(CBState state, const sf::String&& symbolName);
42  void setSymbolColor(CBState state, sf::Color color);
43  void setSymbolTransform(CBState state, const sf::Transform&);
44 
45  void setStateTexture(CBState state, std::shared_ptr<sf::Texture>& texture);
46  void setStateTexture(CBState state, sf::String&& symbolName);
47 
48  void refreshColor(CBState state);
49 
50  void fireAssigner();
51  void fireAssignerNegative();
52 
53 
54 protected:
55  CBState state;
56  CBAssigner assigner;
57  CBAssignerNeg assignerNeg;
58 
59  sf::VertexArray symbol[toId(CBState::Count)];
60  sf::Transform transform[toId(CBState::Count)];
61  sf::Color color[toId(CBState::Count)];
62  std::shared_ptr<sf::Texture> texture[toId(CBState::Count)];
63 
64  void refreshColor(sf::VertexArray& symbol, sf::Color& color);
65 
66 private:
67  virtual void onSetAction(const sf::String& type) override;
68 };
69 
70 
71 typedef std::shared_ptr<Checkbox> CheckboxPtr;
72 
73 
74 #endif // CHECKBOX_HPP
Definition: HaveBackground.hpp:28
Definition: Checkbox.hpp:13
Definition: HaveEnabled.hpp:15
Definition: CBAssigner.hpp:9
Definition: CBAssignerNeg.hpp:9
Definition: HaveOutline.hpp:15
Definition: Pressable.hpp:42
Definition: Checkbox.hpp:24