TGUI  0.8-alpha
SpinButton.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2018 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 
74  static SpinButton::Ptr copy(SpinButton::ConstPtr spinButton);
75 
76 
81  SpinButtonRenderer* getSharedRenderer();
82  const SpinButtonRenderer* getSharedRenderer() const;
83 
89  SpinButtonRenderer* getRenderer();
90  const SpinButtonRenderer* getRenderer() const;
91 
92 
99  void setSize(const Layout2d& size) override;
100  using Widget::setSize;
101 
102 
112  void setMinimum(float minimum);
113 
114 
123  float getMinimum() const;
124 
125 
135  void setMaximum(float maximum);
136 
137 
146  float getMaximum() const;
147 
148 
158  void setValue(float value);
159 
160 
169  float getValue() const;
170 
171 
177  void setStep(float step);
178 
179 
185  float getStep() const;
186 
187 
191  void leftMousePressed(Vector2f pos) override;
192 
196  void leftMouseReleased(Vector2f pos) override;
197 
201  void mouseMoved(Vector2f pos) override;
202 
203 
211  void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
212 
213 
215  protected:
216 
226  Signal& getSignal(std::string signalName) override;
227 
228 
235  void rendererChanged(const std::string& property) override;
236 
237 
241  std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
242 
243 
247  void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
248 
249 
251  // Returns the size of the arrows
253  Vector2f getArrowSize() const;
254 
255 
257  // Makes a copy of the widget
259  Widget::Ptr clone() const override
260  {
261  return std::make_shared<SpinButton>(*this);
262  }
263 
264 
266  public:
267 
268  SignalFloat onValueChange = {"ValueChanged"};
269 
270 
272  protected:
273 
274  // Is the spin button draw vertically (arrows on top of each other)?
275  bool m_verticalScroll = true;
276 
277  float m_minimum = 0;
278  float m_maximum = 10;
279  float m_value = 0;
280  float m_step = 1;
281 
282  // On which arrow is the mouse?
283  bool m_mouseHoverOnTopArrow = false;
284  bool m_mouseDownOnTopArrow = false;
285 
286  Sprite m_spriteArrowUp;
287  Sprite m_spriteArrowUpHover;
288  Sprite m_spriteArrowDown;
289  Sprite m_spriteArrowDownHover;
290 
291  // Cached renderer properties
292  Borders m_bordersCached;
293  Color m_borderColorCached;
294  Color m_backgroundColorCached;
295  Color m_backgroundColorHoverCached;
296  Color m_arrowColorCached;
297  Color m_arrowColorHoverCached;
298  float m_borderBetweenArrowsCached = 0;
299  };
300 
302 }
303 
305 
306 #endif // TGUI_SPIN_BUTTON_HPP
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Definition: Sprite.hpp:43
Wrapper for colors.
Definition: Color.hpp:47
Definition: SpinButtonRenderer.hpp:36
Class to store the position or size of a widget.
Definition: Layout.hpp:243
Definition: Vector2f.hpp:37
Clickable widget.
Definition: ClickableWidget.hpp:39
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
Spin button widget.
Definition: SpinButton.hpp:40
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:76
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:58
std::shared_ptr< const SpinButton > ConstPtr
Shared constant widget pointer.
Definition: SpinButton.hpp:45
Definition: Outline.hpp:38
Widget::Ptr clone() const override
Makes a copy of the widget if you don&#39;t know its exact type.
Definition: SpinButton.hpp:259
std::shared_ptr< SpinButton > Ptr
Shared widget pointer.
Definition: SpinButton.hpp:44