TGUI  v0.6.10
RadioButton.hpp
1 //
3 // TGUI - Texus's Graphical User Interface
4 // Copyright (C) 2012-2015 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_RADIO_BUTTON_HPP
27 #define TGUI_RADIO_BUTTON_HPP
28 
29 
30 #include <TGUI/ClickableWidget.hpp>
31 
33 
34 namespace tgui
35 {
37 
38  class TGUI_API RadioButton : public ClickableWidget
39  {
40  public:
41 
43 
44 
49  RadioButton();
50 
51 
58  RadioButton(const RadioButton& copy);
59 
60 
65  virtual ~RadioButton();
66 
67 
76  RadioButton& operator= (const RadioButton& right);
77 
78 
80  // Makes a copy of the widget by calling the copy constructor.
81  // This function calls new and if you use this function then you are responsible for calling delete.
83  virtual RadioButton* clone();
84 
85 
95  virtual bool load(const std::string& configFileFilename, const std::string& sectionName = "RadioButton");
96 
97 
105  const std::string& getLoadedConfigFile() const;
106 
107 
121  virtual void setPosition(float x, float y);
123 
124 
132  virtual void setSize(float width, float height);
133 
134 
143  virtual sf::Vector2f getSize() const;
144 
145 
154  virtual sf::Vector2f getFullSize() const;
155 
156 
163  virtual void check();
164 
165 
170  virtual void uncheck();
171 
172 
179  bool isChecked() const;
180 
181 
188  void setText(const sf::String& text);
189 
190 
197  sf::String getText() const;
198 
199 
209  void setTextFont(const sf::Font& font);
210 
211 
218  const sf::Font* getTextFont() const;
219 
220 
227  void setTextColor(const sf::Color& color);
228 
229 
236  const sf::Color& getTextColor() const;
237 
238 
246  void setTextSize(unsigned int size);
247 
248 
255  unsigned int getTextSize() const;
256 
257 
264  void allowTextClick(bool acceptTextClick = true);
265 
266 
277  virtual void setTransparency(unsigned char transparency);
278 
279 
283  virtual bool mouseOnWidget(float x, float y);
284 
288  virtual void leftMouseReleased(float x, float y);
289 
293  virtual void keyPressed(const sf::Event::KeyEvent& event);
294 
298  virtual void widgetFocused();
299 
300 
303  // This function is a (slow) way to set properties on the widget, no matter what type it is.
304  // When the requested property doesn't exist in the widget then the functions will return false.
306  virtual bool setProperty(std::string property, const std::string& value);
307 
310  // This function is a (slow) way to get properties of the widget, no matter what type it is.
311  // When the requested property doesn't exist in the widget then the functions will return false.
313  virtual bool getProperty(std::string property, std::string& value) const;
314 
315 
318  // Returns a list of all properties that can be used in setProperty and getProperty.
319  // The second value in the pair is the type of the property (e.g. int, uint, string, ...).
321  virtual std::list< std::pair<std::string, std::string> > getPropertyList() const;
322 
323 
325  protected:
326 
329  // This function is called when the widget is added to a container.
331  virtual void initialize(Container *const container);
332 
333 
336  // Draws the widget on the render target.
338  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
339 
340 
342  public:
343 
348  {
349  Checked = ClickableWidgetCallbacksCount * 1,
350  Unchecked = ClickableWidgetCallbacksCount * 2,
351  SpaceKeyPressed = ClickableWidgetCallbacksCount * 8,
352  ReturnKeyPressed = ClickableWidgetCallbacksCount * 16,
353  AllRadioButtonCallbacks = ClickableWidgetCallbacksCount * 32 - 1,
354  RadioButtonCallbacksCount = ClickableWidgetCallbacksCount * 32
355  };
356 
357 
359  protected:
360 
361  std::string m_LoadedConfigFile;
362 
363  // This is the checked flag. When the radio button is checked then this variable will be true.
364  bool m_Checked;
365 
366  // When this boolean is true (default) then the radio button will also be checked by clicking on the text.
367  bool m_AllowTextClick;
368 
369  // This will contain the text that is written next to radio button.
370  sf::Text m_Text;
371 
372  // This will store the size of the text ( 0 to auto size )
373  unsigned int m_TextSize;
374 
375  Texture m_TextureUnchecked;
376  Texture m_TextureChecked;
377  Texture m_TextureHover;
378  Texture m_TextureFocused;
379 
381  };
382 
384 }
385 
387 
388 #endif // TGUI_RADIO_BUTTON_HPP
Namespace that contains all TGUI functions and classes.
Definition: AnimatedPicture.hpp:33
virtual void setPosition(float x, float y)
Set the position of the widget.
Definition: RadioButton.hpp:38
Definition: TextureManager.hpp:52
RadioButtonCallbacks
Defines specific triggers to RadioButton.
Definition: RadioButton.hpp:347
Definition: ClickableWidget.hpp:38
Parent class for widgets that store multiple widgets.
Definition: Container.hpp:43
Definition: SharedWidgetPtr.hpp:44