TGUI  0.8-dev
SpinButton.hpp
1 //
3 // TGUI - Texus' 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_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(int minimum = 0, int 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(int minimum);
113 
114 
123  int getMinimum() const;
124 
125 
135  void setMaximum(int maximum);
136 
137 
146  int getMaximum() const;
147 
148 
158  void setValue(int value);
159 
160 
169  int getValue() const;
170 
171 
175  void leftMousePressed(Vector2f pos) override;
176 
180  void leftMouseReleased(Vector2f pos) override;
181 
185  void mouseMoved(Vector2f pos) override;
186 
190  void widgetFocused() override;
191 
192 
200  void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
201 
202 
204  protected:
205 
215  Signal& getSignal(std::string signalName) override;
216 
217 
224  void rendererChanged(const std::string& property) override;
225 
226 
230  std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
231 
232 
236  void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
237 
238 
240  // Returns the size of the arrows
242  Vector2f getArrowSize() const;
243 
244 
246  // Makes a copy of the widget
248  Widget::Ptr clone() const override
249  {
250  return std::make_shared<SpinButton>(*this);
251  }
252 
253 
255  public:
256 
257  SignalInt onValueChange = {"ValueChanged"};
258 
259 
261  protected:
262 
263  // Is the spin button draw vertically (arrows on top of each other)?
264  bool m_verticalScroll = true;
265 
266  int m_minimum = 0;
267  int m_maximum = 10;
268  int m_value = 0;
269 
270  // On which arrow is the mouse?
271  bool m_mouseHoverOnTopArrow = false;
272  bool m_mouseDownOnTopArrow = false;
273 
274  Sprite m_spriteArrowUp;
275  Sprite m_spriteArrowUpHover;
276  Sprite m_spriteArrowDown;
277  Sprite m_spriteArrowDownHover;
278 
279  // Cached renderer properties
280  Borders m_bordersCached;
281  Color m_borderColorCached;
282  Color m_backgroundColorCached;
283  Color m_backgroundColorHoverCached;
284  Color m_arrowColorCached;
285  Color m_arrowColorHoverCached;
286  float m_spaceBetweenArrowsCached = 0;
287  };
288 
290 }
291 
293 
294 #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:70
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:248
std::shared_ptr< SpinButton > Ptr
Shared widget pointer.
Definition: SpinButton.hpp:44