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 
84  {
85  return aurora::downcast<SpinButtonRenderer*>(m_renderer.get());
86  }
87 
88 
95  virtual void setSize(const Layout2d& size) override;
97 
98 
108  void setMinimum(int minimum);
109 
110 
119  int getMinimum() const;
120 
121 
131  void setMaximum(int maximum);
132 
133 
142  int getMaximum() const;
143 
144 
154  void setValue(int value);
155 
156 
165  int getValue() const;
166 
167 
174  void setVerticalScroll(bool verticalScroll);
175 
176 
183  bool getVerticalScroll() const;
184 
185 
189  virtual void leftMousePressed(sf::Vector2f pos) override;
190 
194  virtual void leftMouseReleased(sf::Vector2f pos) override;
195 
199  virtual void mouseMoved(sf::Vector2f pos) override;
200 
204  virtual void widgetFocused() override;
205 
206 
214  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
215 
216 
218  protected:
219 
229  virtual Signal& getSignal(std::string&& signalName) override;
230 
231 
238  virtual void rendererChanged(const std::string& property) override;
239 
240 
242  // Returns the size of the arrows
244  sf::Vector2f getArrowSize() const;
245 
246 
248  // Makes a copy of the widget
250  virtual Widget::Ptr clone() const override
251  {
252  return std::make_shared<SpinButton>(*this);
253  }
254 
255 
257  public:
258 
259  SignalWrapper<SignalInt> onValueChange = {"ValueChanged"};
260 
261 
263  protected:
264 
265  // Is the spin button draw vertically (arrows on top of each other)?
266  bool m_verticalScroll = true;
267 
268  int m_minimum = 0;
269  int m_maximum = 10;
270  int m_value = 0;
271 
272  // On which arrow is the mouse?
273  bool m_mouseHoverOnTopArrow = false;
274  bool m_mouseDownOnTopArrow = false;
275 
276  Sprite m_spriteArrowUp;
277  Sprite m_spriteArrowUpHover;
278  Sprite m_spriteArrowDown;
279  Sprite m_spriteArrowDownHover;
280 
281  // Cached renderer properties
282  Borders m_bordersCached;
283  Color m_borderColorCached;
284  Color m_backgroundColorCached;
285  Color m_backgroundColorHoverCached;
286  Color m_arrowColorCached;
287  Color m_arrowColorHoverCached;
288  float m_spaceBetweenArrowsCached = 0;
289  };
290 
292 }
293 
295 
296 #endif // TGUI_SPIN_BUTTON_HPP
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:33
Definition: Sprite.hpp:40
virtual Widget::Ptr clone() const override
Makes a copy of the widget if you don&#39;t know its exact type.
Definition: SpinButton.hpp:250
Wrapper for colors.
Definition: Color.hpp:46
Definition: SpinButtonRenderer.hpp:36
Class to store the position or size of a widget.
Definition: Layout.hpp:205
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
Definition: Transformable.hpp:123
SpinButtonRenderer * getRenderer() const
Returns the renderer, which gives access to functions that determine how the widget is displayed...
Definition: SpinButton.hpp:83
Clickable widget.
Definition: ClickableWidget.hpp:39
Spin button widget.
Definition: SpinButton.hpp:40
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:62
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:61
std::shared_ptr< const SpinButton > ConstPtr
Shared constant widget pointer.
Definition: SpinButton.hpp:45
Definition: Outline.hpp:37
std::shared_ptr< SpinButton > Ptr
Shared widget pointer.
Definition: SpinButton.hpp:44