TGUI  0.8.9
SpinButton.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_SPIN_BUTTON_HPP
27 #define TGUI_SPIN_BUTTON_HPP
28 
29 
30 #include <TGUI/Renderers/SpinButtonRenderer.hpp>
31 #include <TGUI/Widgets/ClickableWidget.hpp>
32 
34 
35 namespace tgui
36 {
40  class TGUI_API SpinButton : public ClickableWidget
41  {
42  public:
43 
44  typedef std::shared_ptr<SpinButton> Ptr;
45  typedef std::shared_ptr<const SpinButton> ConstPtr;
46 
47 
49  // Default constructor
51  SpinButton();
52 
53 
63  static SpinButton::Ptr create(float minimum = 0, float maximum = 10);
64 
65 
75 
76 
82  const SpinButtonRenderer* getSharedRenderer() const;
83 
90  const SpinButtonRenderer* getRenderer() const;
91 
92 
100  void setSize(const Layout2d& size) override;
101  using Widget::setSize;
102 
103 
113  void setMinimum(float minimum);
114 
115 
124  float getMinimum() const;
125 
126 
136  void setMaximum(float maximum);
137 
138 
147  float getMaximum() const;
148 
149 
159  void setValue(float value);
160 
161 
170  float getValue() const;
171 
172 
178  void setStep(float step);
179 
180 
186  float getStep() const;
187 
188 
195  void setVerticalScroll(bool vertical);
196 
197 
202  bool getVerticalScroll() const;
203 
204 
208  void leftMousePressed(Vector2f pos) override;
209 
213  void leftMouseReleased(Vector2f pos) override;
214 
218  void mouseMoved(Vector2f pos) override;
219 
220 
228  void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
229 
230 
232  protected:
233 
243  Signal& getSignal(std::string signalName) override;
244 
245 
252  void rendererChanged(const std::string& property) override;
253 
254 
258  std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
259 
260 
264  void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
265 
266 
268  // Returns the size of the arrows
270  Vector2f getArrowSize() const;
271 
272 
274  // Makes a copy of the widget
276  Widget::Ptr clone() const override
277  {
278  return std::make_shared<SpinButton>(*this);
279  }
280 
281 
283  public:
284 
285  SignalFloat onValueChange = {"ValueChanged"};
286 
287 
289  protected:
290 
291  // Is the spin button draw vertically (arrows on top of each other)?
292  bool m_verticalScroll = true;
293 
294  float m_minimum = 0;
295  float m_maximum = 10;
296  float m_value = 0;
297  float m_step = 1;
298 
299  // On which arrow is the mouse?
300  bool m_mouseHoverOnTopArrow = false;
301  bool m_mouseDownOnTopArrow = false;
302 
303  Sprite m_spriteArrowUp;
304  Sprite m_spriteArrowUpHover;
305  Sprite m_spriteArrowDown;
306  Sprite m_spriteArrowDownHover;
307 
308  // Cached renderer properties
309  Borders m_bordersCached;
310  Color m_borderColorCached;
311  Color m_backgroundColorCached;
312  Color m_backgroundColorHoverCached;
313  Color m_arrowColorCached;
314  Color m_arrowColorHoverCached;
315  float m_borderBetweenArrowsCached = 0;
316  };
317 
319 }
320 
322 
323 #endif // TGUI_SPIN_BUTTON_HPP
Clickable widget.
Definition: ClickableWidget.hpp:40
Wrapper for colors.
Definition: Color.hpp:49
Class to store the position or size of a widget.
Definition: Layout.hpp:260
Definition: Outline.hpp:39
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:231
Definition: SpinButtonRenderer.hpp:37
Spin button widget.
Definition: SpinButton.hpp:41
static SpinButton::Ptr create(float minimum=0, float maximum=10)
Creates a new spin button widget.
void setStep(float step)
Changes how much the value changes on each arrow press.
SpinButtonRenderer * getSharedRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
std::shared_ptr< const SpinButton > ConstPtr
Shared constant widget pointer.
Definition: SpinButton.hpp:45
float getMaximum() const
Returns the maximum value.
std::shared_ptr< SpinButton > Ptr
Shared widget pointer.
Definition: SpinButton.hpp:44
bool getVerticalScroll() const
Returns whether the spin button lies horizontally or vertically.
float getStep() const
Returns the number of positions the thumb advances with each move.
Signal & getSignal(std::string signalName) override
Retrieves a signal based on its name.
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
float getValue() const
Returns the current value.
void setValue(float value)
Changes the current value.
void setVerticalScroll(bool vertical)
Changes whether the spin button lies horizontally or vertically.
float getMinimum() const
Returns the minimum value.
void setSize(const Layout2d &size) override
Changes the size of the spin button.
static SpinButton::Ptr copy(SpinButton::ConstPtr spinButton)
Makes a copy of another spin button.
void rendererChanged(const std::string &property) override
Function called when one of the properties of the renderer is changed.
std::unique_ptr< DataIO::Node > save(SavingRenderersMap &renderers) const override
Saves the widget as a tree node in order to save it to a file.
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition: SpinButton.hpp:276
void setMaximum(float maximum)
Sets a maximum value.
void setMinimum(float minimum)
Sets a minimum value.
SpinButtonRenderer * getRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
void draw(sf::RenderTarget &target, sf::RenderStates states) const override
Draw the widget to a render target.
Definition: Sprite.hpp:46
Definition: Vector2f.hpp:39
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:77
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:37