TGUI  0.9-dev
CheckBox.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2020 Bruno Van de Velde (vdv_b@tgui.eu)
5 //
6 // This software is provided 'as-is', without any express or implied warranty.
7 // In no event will the authors be held liable for any damages arising from the use of this software.
8 //
9 // Permission is granted to anyone to use this software for any purpose,
10 // including commercial applications, and to alter it and redistribute it freely,
11 // subject to the following restrictions:
12 //
13 // 1. The origin of this software must not be misrepresented;
14 // you must not claim that you wrote the original software.
15 // If you use this software in a product, an acknowledgment
16 // in the product documentation would be appreciated but is not required.
17 //
18 // 2. Altered source versions must be plainly marked as such,
19 // and must not be misrepresented as being the original software.
20 //
21 // 3. This notice may not be removed or altered from any source distribution.
22 //
24 
25 
26 #ifndef TGUI_CHECK_BOX_HPP
27 #define TGUI_CHECK_BOX_HPP
28 
29 
30 #include <TGUI/Renderers/CheckBoxRenderer.hpp>
31 #include <TGUI/Widgets/RadioButton.hpp>
32 
34 
35 namespace tgui
36 {
40  class TGUI_API CheckBox : public RadioButton
41  {
42  public:
43 
44  typedef std::shared_ptr<CheckBox> Ptr;
45  typedef std::shared_ptr<const CheckBox> ConstPtr;
46 
47 
49  // Default constructor
51  CheckBox();
52 
53 
62  static CheckBox::Ptr create(String text = "");
63 
64 
73  static CheckBox::Ptr copy(CheckBox::ConstPtr checkbox);
74 
75 
80  CheckBoxRenderer* getSharedRenderer();
81  const CheckBoxRenderer* getSharedRenderer() const;
82 
88  CheckBoxRenderer* getRenderer();
89  const CheckBoxRenderer* getRenderer() const;
90 
91 
101  Vector2f getFullSize() const override;
102 
103 
113  Vector2f getWidgetOffset() const override;
114 
115 
122  void setChecked(bool checked) override;
123 
124 
128  void leftMouseReleased(Vector2f pos) override;
129 
133  void keyPressed(const sf::Event::KeyEvent& event) override;
134 
135 
143  void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
144 
145 
147  protected:
148 
155  void rendererChanged(const String& property) override;
156 
157 
159  // Resets the sizes of the textures if they are used
161  void updateTextureSizes() override;
162 
163 
165  // Makes a copy of the widget
167  Widget::Ptr clone() const override
168  {
169  return std::make_shared<CheckBox>(*this);
170  }
171 
172 
174  private:
175 
176  Texture m_textureUncheckedCached;
177  Texture m_textureCheckedCached;
178 
179 
181  };
182 
184 }
185 
187 
188 #endif // TGUI_CHECK_BOX_HPP
std::shared_ptr< CheckBox > Ptr
Shared widget pointer.
Definition: CheckBox.hpp:44
CheckBox widget.
Definition: CheckBox.hpp:40
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:72
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:35
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition: CheckBox.hpp:167
Definition: CheckBoxRenderer.hpp:36
Definition: Texture.hpp:42
Wrapper class to store strings.
Definition: String.hpp:70
Radio button widget.
Definition: RadioButton.hpp:41
std::shared_ptr< const CheckBox > ConstPtr
Shared constant widget pointer.
Definition: CheckBox.hpp:45