CheckBox.hpp
1 /*
2  * Copyright © 2013 mathdu07
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef CHECKBOX_H_
19 #define CHECKBOX_H_
20 
21 #include <SFML/UI/AbstractButton.hpp>
22 #include <SFML/UI/IText.hpp>
23 
24 namespace sf
25 {
26 namespace ui
27 {
28 
29 class CheckBox : public AbstractButton, public IText
30 {
31 public:
39  CheckBox(bool selected = false);
40 
51  CheckBox(sf::Texture const &texture, sf::Texture const &textureSelected, bool selected = false);
52 
64  CheckBox(sf::Texture const &texture, sf::Texture const &textureSelected, sf::Font const& font, sf::String name = "", bool selected = false);
65 
66  virtual ~CheckBox();
67  //CONSTRUCTORS/DESTRUCTORS -------------------------------------------
68 
69  //--------------------------------------------------------------------
70 
71  //METHODS ------------------------------------------------------------
72 protected:
79  virtual void onClick();
80 
87  virtual void updateCoord();
88 
94  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
95 
96 public:
105  virtual void updateFixed(sf::Time delta);
106  //--------------------------------------------------------------------
107 
108  //GETTERS/SETTERS ----------------------------------------------------
114  bool isSelected() const;
115 
123  void setSelected(bool selected);
124 
130  virtual sf::Vector2f getSize() const;
131 
137  virtual const sf::String& getText() const;
138 
147  virtual void setText(sf::String const &text);
148 
154  virtual const sf::Font* getFont() const;
155 
161  virtual void setFont(sf::Font const &font);
162 
168  virtual unsigned int getFontSize() const;
169 
177  virtual void setFontSize(unsigned int size);
178 
184  virtual sf::Color getFontColor() const;
185 
193  virtual void setFontColor(sf::Color color);
194  //--------------------------------------------------------------------
195 
196  //FIELDS -------------------------------------------------------------
197 protected:
198  sf::Text m_text;
199  //--------------------------------------------------------------------
200 };
201 
202 } /* namespace ui */
203 } /* namespace sf */
204 #endif /* CHECKBOX_H_ */
205 
virtual sf::Vector2f getSize() const
virtual void onClick()
Called when the button is clicked That defines whether the check box is selected or not...
A box which can be checked or not.
Definition: CheckBox.hpp:29
virtual void setFontSize(unsigned int size)
Set the font's size of the component.
virtual void draw(sf::RenderTarget &target, sf::RenderStates states) const
Draw the component to the render target.
virtual void setFont(sf::Font const &font)
Sets the font of the component's text.
virtual unsigned int getFontSize() const
virtual const sf::String & getText() const
virtual void setFontColor(sf::Color color)
Sets the color's font of the text.
virtual void setText(sf::String const &text)
Sets the text's string of the component Don't forget to set the font.
virtual sf::Color getFontColor() const
virtual void updateCoord()
Called when the component need update its geometry Inherit when you need to update some sprite...
virtual const sf::Font * getFont() const
CheckBox(bool selected=false)
Creates a Check Box without texture.
Abstract class for all component that are button-like.
An interface that allow component to have a text.
Definition: IText.hpp:28
virtual void updateFixed(sf::Time delta)
Update the component with the main loop's frequency Can be useful for animation, or time's needed stu...
bool isSelected() const
void setSelected(bool selected)
Sets if the check box is selected or not.