Gorgon Game Engine
Checkbox.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../UI/ComponentStackWidget.h"
4 #include "../UI/TwoStateControl.h"
5 #include "../Property.h"
6 #include "Registry.h"
7 
8 namespace Gorgon { namespace Widgets {
9 
11  public:
12  Checkbox(const Checkbox &) = delete;
13 
14 
16  Checkbox(Registry::Active()[type], "")
17  {
18  }
19 
21  Checkbox(Registry::Active()[type], state)
22  {
23  }
24 
25  explicit Checkbox(std::string text, Registry::TemplateType type = Registry::Checkbox_Regular) :
26  Checkbox(Registry::Active()[type], text)
27  {
28  }
29 
30  explicit Checkbox(const char *text, Registry::TemplateType type = Registry::Checkbox_Regular) :
31  Checkbox(Registry::Active()[type], text)
32  {
33  }
34 
35  template<class F_>
37  Checkbox(Registry::Active()[type], "", changed)
38  {
39  }
40 
41  template<class F_>
42  explicit Checkbox(std::string text, F_ changed, Registry::TemplateType type = Registry::Checkbox_Regular):
43  Checkbox(Registry::Active()[type], text, changed) {
44  }
45 
46  template<class F_>
47  explicit Checkbox(const char *text, F_ changed, Registry::TemplateType type = Registry::Checkbox_Regular):
48  Checkbox(Registry::Active()[type], text, changed) {
49  }
50 
51  explicit Checkbox(std::string text, bool state, Registry::TemplateType type = Registry::Checkbox_Regular) :
52  Checkbox(Registry::Active()[type], text, state)
53  {
54  }
55 
56  explicit Checkbox(const char *text, bool state, Registry::TemplateType type = Registry::Checkbox_Regular) :
57  Checkbox(Registry::Active()[type], text, state)
58  {
59  }
60 
61  template<class F_>
62  explicit Checkbox(bool state, F_ changed, Registry::TemplateType type = Registry::Checkbox_Regular) :
63  Checkbox(Registry::Active()[type], "", state, changed)
64  {
65  }
66 
67  template<class F_>
68  explicit Checkbox(std::string text, bool state, F_ changed, Registry::TemplateType type = Registry::Checkbox_Regular) :
69  Checkbox(Registry::Active()[type], text, state, changed)
70  {
71  }
72 
73  explicit Checkbox(const UI::Template &temp, std::string text = "") : Checkbox(temp, text, false) {}
74 
75  Checkbox(const UI::Template &temp, const char *text) : Checkbox(temp, std::string(text), false) {}
76 
77  template<class F_>
78  Checkbox(const UI::Template &temp, F_ changed) : Checkbox(temp, "", false, changed) { }
79 
80  template<class F_>
81  Checkbox(const UI::Template &temp, std::string text, F_ changed) : Checkbox(temp, text, false, changed) { }
82 
83  template<class F_>
84  Checkbox(const UI::Template &temp, const char *text, F_ changed) : Checkbox(temp, std::string(text), false, changed) { }
85 
86  template<class F_>
87  Checkbox(const UI::Template &temp, bool state, F_ changed) : Checkbox(temp, "", state, changed) { }
88 
89 
90  template<class F_>
91  Checkbox(const UI::Template &temp, std::string text, bool state, F_ changed) : Checkbox(temp, text, state) {
92  ChangedEvent.Register(changed);
93  }
94 
95  template<class F_>
96  Checkbox(const UI::Template &temp, const char *text, bool state, F_ changed) : Checkbox(temp, std::string(text), state, changed) { }
97 
98  Checkbox(const UI::Template &temp, bool state) : Checkbox(temp, "", state) {}
99 
100  Checkbox(const UI::Template &temp, std::string text, bool state);
101 
102  Checkbox(const UI::Template &temp, const char *text, bool state) : Checkbox(temp, std::string(text), state) { }
103 
104  Checkbox &operator =(bool value) { SetState(value); return *this; }
105 
106  operator bool() { return GetState(); }
107 
108  virtual ~Checkbox();
109 
110  void SetText(const std::string &value);
111 
112  std::string GetText() const { return text; }
113 
115  virtual bool GetState() const override { return state; }
116 
118  virtual bool SetState(bool value, bool force = false) override;
119 
120  virtual bool Activate() override;
121 
122  bool KeyEvent(Input::Key key, float state) override;
123 
125 
126  Event<Checkbox, bool /*state*/> ChangedEvent;
127 
128  private:
129  std::string text;
130  bool spacedown = false;
131  bool state = false;
132 
133  protected:
134  virtual bool allowfocus() const override;
135 
136  };
137 
138 } }
139 
Gorgon::UI::Widget::HasParent
bool HasParent() const
Returns if this widget has a parent.
Definition: Widget.h:140
Gorgon::UI::TwoStateControl::Clear
bool Clear()
Changes the state of the checkbox.
Definition: TwoStateControl.h:32
Gorgon::UI::ComponentStackWidget::stack
ComponentStack & stack
Definition: ComponentStackWidget.h:76
Gorgon::Widgets::Checkbox::ChangedEvent
Event< Checkbox, bool > ChangedEvent
Definition: Checkbox.h:126
Gorgon::Widgets::Checkbox::GetText
std::string GetText() const
Definition: Checkbox.h:112
Gorgon::Widgets::Checkbox::Checkbox
Checkbox(const UI::Template &temp, bool state, F_ changed)
Definition: Checkbox.h:87
Gorgon::UI::Widget::Focus
bool Focus()
Transfers the focus to this widget.
Definition: Widget.cpp:13
Gorgon::UI::ComponentStack::SetData
void SetData(ComponentTemplate::DataEffect effect, const std::string &text)
Sets the data for a specific data effect.
Definition: ComponentStack.cpp:725
Gorgon::Widgets::Checkbox::Checkbox
Checkbox(F_ changed, Registry::TemplateType type=Registry::Checkbox_Regular)
Definition: Checkbox.h:36
Gorgon::Input::Keyboard::Keycodes::Space
constexpr Key Space
Definition: Keyboard.h:59
Gorgon::Event
This class provides event mechanism.
Definition: Event.h:134
Gorgon::Widgets::Checkbox::Checkbox
Checkbox(const char *text, F_ changed, Registry::TemplateType type=Registry::Checkbox_Regular)
Definition: Checkbox.h:47
Gorgon::UI::TwoStateControl::Toggle
bool Toggle()
Changes the state of the checkbox.
Definition: TwoStateControl.h:42
Gorgon::Input::Keyboard::CurrentModifier
Modifier CurrentModifier
Current keyboard modifier, this is a global value.
Definition: Input.cpp:7
Gorgon::UI::Template
This class stores visual information about a widget template.
Definition: Template.h:392
Gorgon::UI::WidgetContainer::CurrentFocusStrategy
FocusStrategy CurrentFocusStrategy() const
Returns the active focus strategy. This function will not return Inherit.
Definition: WidgetContainer.h:340
Gorgon::Widgets::Registry::Checkbox_Regular
@ Checkbox_Regular
Definition: Registry.h:25
Gorgon::TextualProperty
Supports everything that string class supports including +, +=, length()
Definition: Property.h:562
Gorgon::Widgets::Checkbox::SetState
virtual bool SetState(bool value, bool force=false) override
Changes the state of the checkbox.
Definition: Checkbox.cpp:107
Gorgon::Resource::GID::Text
constexpr Type Text
Stores text data, no longer a resource.
Definition: GID.h:134
Gorgon::Widgets::Checkbox::Checkbox
Checkbox(const UI::Template &temp, F_ changed)
Definition: Checkbox.h:78
Gorgon::Widgets::Checkbox::Checkbox
Checkbox(Registry::TemplateType type=Registry::Checkbox_Regular)
Definition: Checkbox.h:15
Gorgon::Widgets::Checkbox::Text
TextualProperty< Checkbox, std::string, &Checkbox::GetText, &Checkbox::SetText > Text
Definition: Checkbox.h:124
Gorgon::Widgets::Checkbox::Activate
virtual bool Activate() override
Activates the widget.
Definition: Checkbox.cpp:45
Gorgon::UI::TwoStateControl::StateChangingEvent
Event< TwoStateControl, bool, bool & > StateChangingEvent
This event.
Definition: TwoStateControl.h:51
Gorgon::UI::ComponentStack::RemoveCondition
void RemoveCondition(ComponentCondition condition, bool transition=true)
Removes a condition and its associated components.
Definition: ComponentStack.h:54
Gorgon::Widgets::Registry::TemplateType
TemplateType
This enum lists all possible template types.
Definition: Registry.h:18
Gorgon::UI::ComponentTemplate::Text
@ Text
Works only for TextholderTemplate, data will affect the text that is displayed.
Definition: Template.h:651
Gorgon::UI::TwoStateControl::Check
bool Check()
Changes the state of the widget.
Definition: TwoStateControl.h:29
Gorgon::Input::Key
int Key
A type to represent an input key.
Definition: Input.h:14
Gorgon::UI::Widget::GetParent
WidgetContainer & GetParent() const
Returns the parent of this widget, throws if it does not have a parent.
Definition: Widget.cpp:30
Gorgon
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
Gorgon::Widgets::Checkbox
Definition: Checkbox.h:10
Gorgon::Widgets::Checkbox::Checkbox
Checkbox(const UI::Template &temp, std::string text="")
Definition: Checkbox.h:73
Gorgon::Widgets::Checkbox::SetText
void SetText(const std::string &value)
Definition: Checkbox.cpp:40
Checkbox.h
Gorgon::Widgets::Checkbox::Checkbox
Checkbox(std::string text, bool state, Registry::TemplateType type=Registry::Checkbox_Regular)
Definition: Checkbox.h:51
Gorgon::Widgets::Checkbox::Checkbox
Checkbox(std::string text, bool state, F_ changed, Registry::TemplateType type=Registry::Checkbox_Regular)
Definition: Checkbox.h:68
Gorgon::Input::Keyboard::Keycodes::Numpad_Plus
constexpr Key Numpad_Plus
Definition: Keyboard.h:132
Gorgon::UI::ComponentStack::AddCondition
void AddCondition(ComponentCondition condition, bool transition=true)
Adds a condition and its associated components to the stack.
Definition: ComponentStack.h:48
Gorgon::Widgets::Checkbox::~Checkbox
virtual ~Checkbox()
Definition: Checkbox.cpp:37
Gorgon::UI::TwoStateControl
This class is designed to be the interface class for all checkbox like UI elements.
Definition: TwoStateControl.h:13
Gorgon::Widgets::Checkbox::Checkbox
Checkbox(const UI::Template &temp, std::string text, bool state, F_ changed)
Definition: Checkbox.h:91
Registry.h
Gorgon::UI::ComponentStack::SetClickEvent
void SetClickEvent(std::function< void(ComponentTemplate::Tag, Geometry::Point, Input::Mouse::Button)> handler)
Sets the mouse down event.
Definition: ComponentStack.h:490
Gorgon::UI::Active
@ Active
This is for widgets that can be activated, like a count down timer.
Definition: Template.h:245
Gorgon::Widgets::Checkbox::Checkbox
Checkbox(const UI::Template &temp, std::string text, F_ changed)
Definition: Checkbox.h:81
Gorgon::Widgets::Checkbox::Checkbox
Checkbox(const UI::Template &temp, const char *text)
Definition: Checkbox.h:75
Gorgon::UI::State2
@ State2
Second state of the widget, first state is Always.
Definition: Template.h:201
Gorgon::Widgets::Checkbox::Checkbox
Checkbox(bool state, F_ changed, Registry::TemplateType type=Registry::Checkbox_Regular)
Definition: Checkbox.h:62
Gorgon::Widgets::Checkbox::Checkbox
Checkbox(const Checkbox &)=delete
Gorgon::Widgets::Checkbox::Checkbox
Checkbox(bool state, Registry::TemplateType type=Registry::Checkbox_Regular)
Definition: Checkbox.h:20
Gorgon::Widgets::Checkbox::allowfocus
virtual bool allowfocus() const override
Should return true if the widget can be focused.
Definition: Checkbox.cpp:54
Gorgon::Widgets::Checkbox::Checkbox
Checkbox(const UI::Template &temp, const char *text, bool state)
Definition: Checkbox.h:102
Gorgon::Widgets::Checkbox::Checkbox
Checkbox(const char *text, Registry::TemplateType type=Registry::Checkbox_Regular)
Definition: Checkbox.h:30
Gorgon::Widgets::Checkbox::Checkbox
Checkbox(const char *text, bool state, Registry::TemplateType type=Registry::Checkbox_Regular)
Definition: Checkbox.h:56
Gorgon::UI::WidgetContainer::AllowAll
@ AllowAll
All widgets that can be focused are allowed to receive focus, including buttons but not labels.
Definition: WidgetContainer.h:48
Gorgon::Widgets::Checkbox::Checkbox
Checkbox(const UI::Template &temp, const char *text, F_ changed)
Definition: Checkbox.h:84
Gorgon::Widgets::Checkbox::Checkbox
Checkbox(std::string text, F_ changed, Registry::TemplateType type=Registry::Checkbox_Regular)
Definition: Checkbox.h:42
Gorgon::UI::WidgetContainer::FocusNext
bool FocusNext()
Focuses the next widget that accepts focus.
Definition: WidgetContainer.cpp:141
Gorgon::Widgets::Checkbox::Checkbox
Checkbox(std::string text, Registry::TemplateType type=Registry::Checkbox_Regular)
Definition: Checkbox.h:25
Gorgon::UI::ComponentStack::HandleMouse
void HandleMouse(Input::Mouse::Button accepted=Input::Mouse::Button::All)
This function instructs stack to handle mouse to automatically change hover/down states,...
Definition: ComponentStack.cpp:1023
Gorgon::Widgets::Checkbox::KeyEvent
bool KeyEvent(Input::Key key, float state) override
This function should be called whenever a key is pressed or released.
Definition: Checkbox.cpp:59
Gorgon::UI::ComponentStack::SetMouseDownEvent
void SetMouseDownEvent(std::function< void(ComponentTemplate::Tag, Geometry::Point, Input::Mouse::Button)> handler)
Sets the mouse down event.
Definition: ComponentStack.h:465
Gorgon::UI::ComponentStackWidget
This class acts as a widget base that uses component stack to handle rendering, resizing and other op...
Definition: ComponentStackWidget.h:14
Gorgon::Widgets::Checkbox::Checkbox
Checkbox(const UI::Template &temp, bool state)
Definition: Checkbox.h:98
Gorgon::Input::Keyboard::Keycodes::Left
constexpr Key Left
Definition: Keyboard.h:62
Gorgon::Input::Keyboard::Keycodes::Numpad_Minus
constexpr Key Numpad_Minus
Definition: Keyboard.h:133
Gorgon::Widgets::Registry
This class stores templates for elements.
Definition: Registry.h:12
Gorgon::Widgets::Checkbox::GetState
virtual bool GetState() const override
Returns the state of the checkbox.
Definition: Checkbox.h:115
Gorgon::Widgets::Checkbox::Checkbox
Checkbox(const UI::Template &temp, const char *text, bool state, F_ changed)
Definition: Checkbox.h:96
Gorgon::Widgets::Checkbox::operator=
Checkbox & operator=(bool value)
Definition: Checkbox.h:104
Gorgon::Input::Keyboard::Keycodes::Down
constexpr Key Down
Definition: Keyboard.h:65
Gorgon::UI::ComponentStack::SetMouseUpEvent
void SetMouseUpEvent(std::function< void(ComponentTemplate::Tag, Geometry::Point, Input::Mouse::Button)> handler)
Sets the mouse up event.
Definition: ComponentStack.h:478