TGUI  v0.5.2
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
Checkbox.hpp
1 //
3 // TGUI - Texus's Graphical User Interface
4 // Copyright (C) 2012 Bruno Van de Velde (VDV_B@hotmail.com)
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_CHECKBOX_INCLUDED_
27 #define _TGUI_CHECKBOX_INCLUDED_
28 
30 
31 namespace tgui
32 {
34 
35  struct TGUI_API Checkbox : public OBJECT
36  {
40  Checkbox();
41 
42 
46  Checkbox(const Checkbox& copy);
47 
48 
52  virtual ~Checkbox();
53 
54 
58  Checkbox& operator= (const Checkbox& right);
59 
60 
64  virtual void initialize();
65 
66 
70  virtual Checkbox* clone();
71 
72 
85  virtual bool load(const std::string& pathname);
86 
87 
94  virtual void setSize(float width, float height);
95 
96 
100  virtual Vector2u getSize() const;
101 
102 
106  virtual Vector2f getScaledSize() const;
107 
108 
114  virtual std::string getLoadedPathname() const;
115 
116 
120  virtual void check();
121 
122 
126  virtual void uncheck();
127 
128 
132  virtual bool isChecked() const;
133 
134 
138  virtual void setText(const sf::String& text);
139 
140 
144  virtual sf::String getText() const;
145 
146 
153  virtual void setTextFont(const sf::Font& font);
154 
155 
159  virtual const sf::Font* getTextFont() const;
160 
161 
165  virtual void setTextColor(const sf::Color& color);
166 
167 
171  virtual const sf::Color& getTextColor() const;
172 
173 
179  virtual void setTextSize(unsigned int size);
180 
181 
185  virtual unsigned int getTextSize() const;
186 
187 
189  // These functions are used to receive callback from EventManager.
190  // You normally don't need them, but you can use them to simulate an event.
192  virtual bool mouseOnObject(float x, float y);
193  virtual void leftMousePressed(float x, float y);
194  virtual void leftMouseReleased(float x, float y);
195  virtual void mouseMoved(float x, float y);
196  virtual void keyPressed(sf::Keyboard::Key key);
197  virtual void objectFocused();
198 
199 
201  protected:
202 
203 
205  // Because this struct is derived from sf::Drawable, you can just call the draw function from your sf::RenderTarget.
206  // This function will be called and it will draw the checkbox on the render target.
208  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
209 
210 
212  public:
213 
216 
218  protected:
219 
220  // This is the checked flag. When the checkbox is checked then this variable will be true.
221  bool m_Checked;
222 
223  // This will contain the text that is written next to checkbox.
224  sf::Text m_Text;
225 
226  // This will store the size of the text ( 0 to auto size )
227  unsigned int m_TextSize;
228 
229  // The size of the checkbox
230  Vector2f m_Size;
231 
232  // The SFML textures
233  sf::Texture* m_TextureUnchecked;
234  sf::Texture* m_TextureChecked;
235  sf::Texture* m_TextureMouseHover;
236  sf::Texture* m_TextureFocused;
237 
238  // The SFML sprites
239  sf::Sprite m_SpriteUnchecked;
240  sf::Sprite m_SpriteChecked;
241  sf::Sprite m_SpriteMouseHover;
242  sf::Sprite m_SpriteFocused;
243 
244  // The pathname used to load the checkbox
245  std::string m_LoadedPathname;
246 
247 
249  };
250 
252 
253 }
254 
256 
257 #endif //_TGUI_CHECKBOX_INCLUDED_
The parent struct for every object.
Definition: Objects.hpp:36
Definition: Checkbox.hpp:35
bool allowTextClick
When this boolean is true (default) then the checkbox will also be checked/unchecked by clicking on t...
Definition: Checkbox.hpp:215