TGUI  0.7.8
RadioButton.hpp
1
2//
3// TGUI - Texus's Graphical User Interface
4// Copyright (C) 2012-2017 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/Widgets/Label.hpp>
31
33
34namespace tgui
35{
36 class RadioButtonRenderer;
37
53 class TGUI_API RadioButton : public ClickableWidget
54 {
55 public:
56
57 typedef std::shared_ptr<RadioButton> Ptr;
58 typedef std::shared_ptr<const RadioButton> ConstPtr;
59
60
62 // Default constructor
65
66
74
75
85
86
93 std::shared_ptr<RadioButtonRenderer> getRenderer() const
94 {
95 return std::static_pointer_cast<RadioButtonRenderer>(m_renderer);
96 }
97
98
111 virtual void setPosition(const Layout2d& position) override;
113
114
121 virtual void setSize(const Layout2d& size) override;
123
124
133 virtual sf::Vector2f getFullSize() const override;
134
135
144 virtual void setFont(const Font& font) override;
145
146
153 virtual void check();
154
155
160 virtual void uncheck();
161
162
169 bool isChecked() const
170 {
171 return m_checked;
172 }
173
174
181 void setText(const sf::String& text);
182
183
190 sf::String getText() const
191 {
192 return m_text.getText();
193 }
194
195
203 void setTextSize(unsigned int size);
204
205
212 unsigned int getTextSize() const
213 {
214 return m_text.getTextSize();
215 }
216
217
224 void allowTextClick(bool acceptTextClick = true);
225
226
233 virtual void setOpacity(float opacity) override;
234
235
239 virtual bool mouseOnWidget(float x, float y) const override;
240
244 virtual void leftMouseReleased(float x, float y) override;
245
249 virtual void keyPressed(const sf::Event::KeyEvent& event) override;
250
254 virtual void widgetFocused() override;
255
256
258 protected:
259
272 virtual void reload(const std::string& primary = "", const std::string& secondary = "", bool force = false) override;
273
274
276 // Makes a copy of the widget
278 virtual Widget::Ptr clone() const override
279 {
280 return std::make_shared<RadioButton>(*this);
281 }
282
283
285 // This function is called when the mouse enters the widget. If requested, a callback will be send.
287 virtual void mouseEnteredWidget() override;
288
289
291 // This function is called when the mouse leaves the widget. If requested, a callback will be send.
293 virtual void mouseLeftWidget() override;
294
295
297 // Draws the widget on the render target.
299 virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
300
301
303 protected:
304
305 // This is the checked flag. When the radio button is checked then this variable will be true.
306 bool m_checked = false;
307
308 // When this boolean is true (default) then the radio button will also be checked by clicking on the text.
309 bool m_allowTextClick = true;
310
311 // This will contain the text that is written next to radio button.
312 Label m_text;
313
314 // This will store the size of the text ( 0 to auto size )
315 unsigned int m_textSize = 0;
316
317 friend class RadioButtonRenderer;
318 friend class CheckBoxRenderer;
319
321 };
322
323
325
326 class TGUI_API RadioButtonRenderer : public WidgetRenderer, public WidgetPadding
327 {
328 public:
329
336 RadioButtonRenderer(RadioButton* radioButton) : m_radioButton{radioButton} {}
337
338
348 virtual void setProperty(std::string property, const std::string& value) override;
349
350
361 virtual void setProperty(std::string property, ObjectConverter&& value) override;
362
363
373 virtual ObjectConverter getProperty(std::string property) const override;
374
375
382 virtual std::map<std::string, ObjectConverter> getPropertyValuePairs() const override;
383
384
396 void setTextColor(const Color& color);
397
398
405 void setTextColorNormal(const Color& color);
406
407
414 void setTextColorHover(const Color& color);
415
416
432 void setBackgroundColor(const Color& color);
433
434
445 void setBackgroundColorNormal(const Color& color);
446
447
458 void setBackgroundColorHover(const Color& color);
459
460
477 void setForegroundColor(const Color& color);
478
479
493 void setForegroundColorNormal(const Color& color);
494
495
507 void setForegroundColorHover(const Color& color);
508
509
523 void setCheckColor(const Color& color);
524
525
534 void setCheckColorNormal(const Color& color);
535
536
545 void setCheckColorHover(const Color& color);
546
547
557 void setUncheckedTexture(const Texture& texture);
558
559
569 void setCheckedTexture(const Texture& texture);
570
571
581 void setUncheckedHoverTexture(const Texture& texture);
582
583
593 void setCheckedHoverTexture(const Texture& texture);
594
595
605 void setFocusedTexture(const Texture& texture);
606
607
609 // Draws the widget on the render target.
611 virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
612
613
615 protected:
616
618 // Makes a copy of the renderer
620 virtual std::shared_ptr<WidgetRenderer> clone(Widget* widget) override;
621
622
624 protected:
625
626 RadioButton* m_radioButton;
627
628 Texture m_textureUnchecked;
629 Texture m_textureChecked;
630 Texture m_textureUncheckedHover;
631 Texture m_textureCheckedHover;
632 Texture m_textureFocused;
633
634 sf::Color m_textColorNormal;
635 sf::Color m_textColorHover;
636
637 sf::Color m_backgroundColorNormal;
638 sf::Color m_backgroundColorHover;
639
640 sf::Color m_foregroundColorNormal;
641 sf::Color m_foregroundColorHover;
642
643 sf::Color m_checkColorNormal;
644 sf::Color m_checkColorHover;
645
646 friend class RadioButton;
647
649 };
650
652}
653
655
656#endif // TGUI_RADIO_BUTTON_HPP
Definition: CheckBox.hpp:137
Clickable widget.
Definition: ClickableWidget.hpp:56
Implicit converter for colors.
Definition: Color.hpp:40
Definition: Font.hpp:38
Label widget.
Definition: Label.hpp:50
Class to store the position or size of a widget.
Definition: Layout.hpp:255
Implicit converter for settable properties.
Definition: ObjectConverter.hpp:43
Definition: RadioButton.hpp:327
void setForegroundColor(const Color &color)
Changes the foreground color.
virtual std::map< std::string, ObjectConverter > getPropertyValuePairs() const override
Get a map with all properties and their values.
virtual ObjectConverter getProperty(std::string property) const override
Retrieve the value of a certain property.
void setCheckedHoverTexture(const Texture &texture)
Change the image that is displayed when the checkbox is checked and the mouse is on top of the checkb...
void setFocusedTexture(const Texture &texture)
Change the image that is displayed on top of the checkbox when it is focused.
void setUncheckedHoverTexture(const Texture &texture)
Change the image that is displayed when the checkbox is not checked and the mouse is on top of the ch...
void setTextColorHover(const Color &color)
Changes the color of the text in hover state (mouse is standing on top of the radio button).
void setCheckedTexture(const Texture &texture)
Change the image that is displayed when the checkbox is checked.
void setCheckColorHover(const Color &color)
Changes the color that is used to fill the radio button when it is checked (mouse is on top of radio ...
void setForegroundColorNormal(const Color &color)
Changes the foreground color in normal state (mouse is not on top of the radio button).
virtual void setProperty(std::string property, const std::string &value) override
Change a property of the renderer.
void setTextColor(const Color &color)
Changes the color of the text.
RadioButtonRenderer(RadioButton *radioButton)
Constructor.
Definition: RadioButton.hpp:336
virtual void setProperty(std::string property, ObjectConverter &&value) override
Change a property of the renderer.
void setCheckColor(const Color &color)
Changes the color that is used to fill the radio button when it is checked.
void setBackgroundColor(const Color &color)
Changes the background color.
void setBackgroundColorNormal(const Color &color)
Changes the background color in normal state (mouse is not on top of the radio button).
void setForegroundColorHover(const Color &color)
Changes the foreground color in hover state (mouse is standing on top of the radio button).
void setCheckColorNormal(const Color &color)
Changes the color that is used to fill the radio button when it is checked (mouse is not on radio but...
void setBackgroundColorHover(const Color &color)
Changes the background color in hover state (mouse is standing on top of the radio button).
void setTextColorNormal(const Color &color)
Changes the color of the text in normal state (mouse not on top of the radio button).
void setUncheckedTexture(const Texture &texture)
Change the image that is displayed when the checkbox is not checked.
Radio button widget.
Definition: RadioButton.hpp:54
void setText(const sf::String &text)
Changes the text of the radio button.
bool isChecked() const
Returns whether the radio button is checked or not.
Definition: RadioButton.hpp:169
sf::String getText() const
Returns the text of the radio button.
Definition: RadioButton.hpp:190
virtual void uncheck()
Unchecks the radio button.
std::shared_ptr< RadioButton > Ptr
Shared widget pointer.
Definition: RadioButton.hpp:57
virtual sf::Vector2f getFullSize() const override
Returns the full size of the radio button.
unsigned int getTextSize() const
Returns the character size of the text.
Definition: RadioButton.hpp:212
std::shared_ptr< const RadioButton > ConstPtr
Shared constant widget pointer.
Definition: RadioButton.hpp:58
virtual void setSize(const Layout2d &size) override
Changes the size of the radio button.
virtual void setFont(const Font &font) override
Changes the font of the text in the widget.
virtual Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition: RadioButton.hpp:278
std::shared_ptr< RadioButtonRenderer > getRenderer() const
Returns the renderer, which gives access to functions that determine how the widget is displayed.
Definition: RadioButton.hpp:93
void setTextSize(unsigned int size)
Changes the character size of the text.
static RadioButton::Ptr copy(RadioButton::ConstPtr radioButton)
Makes a copy of another radio button.
void allowTextClick(bool acceptTextClick=true)
Allow (or disallow) the radio button to be checked/unchecked by clicking on the text next to the radi...
virtual void setPosition(const Layout2d &position) override
Set the position of the widget.
virtual void setOpacity(float opacity) override
Changes the opacity of the widget.
static RadioButton::Ptr create()
Creates a new radio button widget.
virtual void reload(const std::string &primary="", const std::string &secondary="", bool force=false) override
Reload the widget.
virtual void check()
Checks the radio button.
Definition: Texture.hpp:45
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
virtual void setPosition(const Layout2d &position)
set the position of the widget
Parent class for every widget that has padding.
Definition: Borders.hpp:211
Base class for all renderer classes.
Definition: Widget.hpp:683
The parent class for every widget.
Definition: Widget.hpp:72
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:75
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:34