TGUI  v0.7.5
SpinButton.hpp
1 //
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_SPIN_BUTTON_HPP
27 #define TGUI_SPIN_BUTTON_HPP
28 
29 
30 #include <TGUI/Widgets/ClickableWidget.hpp>
31 
33 
34 namespace tgui
35 {
36  class SpinButtonRenderer;
37 
49  class TGUI_API SpinButton : public ClickableWidget
50  {
51  public:
52 
53  typedef std::shared_ptr<SpinButton> Ptr;
54  typedef std::shared_ptr<const SpinButton> ConstPtr;
55 
56 
58  // Default constructor
60  SpinButton();
61 
62 
72  static SpinButton::Ptr create(int minimum = 0, int maximum = 10);
73 
74 
83  static SpinButton::Ptr copy(SpinButton::ConstPtr spinButton);
84 
85 
92  std::shared_ptr<SpinButtonRenderer> getRenderer() const
93  {
94  return std::static_pointer_cast<SpinButtonRenderer>(m_renderer);
95  }
96 
97 
110  virtual void setPosition(const Layout2d& position) override;
112 
113 
120  virtual void setSize(const Layout2d& size) override;
122 
123 
132  virtual sf::Vector2f getFullSize() const override;
133 
134 
144  void setMinimum(int minimum);
145 
146 
156  void setMaximum(int maximum);
157 
158 
168  void setValue(int value);
169 
170 
179  int getMinimum() const
180  {
181  return m_minimum;
182  }
183 
184 
193  int getMaximum() const
194  {
195  return m_maximum;
196  }
197 
198 
207  int getValue() const
208  {
209  return m_value;
210  }
211 
212 
219  void setVerticalScroll(bool verticalScroll);
220 
221 
228  bool getVerticalScroll() const
229  {
230  return m_verticalScroll;
231  }
232 
233 
240  virtual void setOpacity(float opacity) override;
241 
242 
251  virtual sf::Vector2f getWidgetOffset() const override;
252 
253 
257  virtual void leftMousePressed(float x, float y) override;
258 
262  virtual void leftMouseReleased(float x, float y) override;
263 
267  virtual void mouseMoved(float x, float y) override;
268 
272  virtual void widgetFocused() override;
273 
274 
276  protected:
277 
290  virtual void reload(const std::string& primary = "", const std::string& secondary = "", bool force = false) override;
291 
292 
294  // Makes a copy of the widget
296  virtual Widget::Ptr clone() const override
297  {
298  return std::make_shared<SpinButton>(*this);
299  }
300 
301 
303  // Draws the widget on the render target.
305  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
306 
307 
309  protected:
310 
311  // Is the spin button draw vertically (arrows on top of each other)?
312  bool m_verticalScroll = true;
313 
314  int m_minimum = 0;
315  int m_maximum = 10;
316  int m_value = 0;
317 
318  // On which arrow is the mouse?
319  bool m_mouseHoverOnTopArrow = false;
320  bool m_mouseDownOnTopArrow = false;
321 
322  friend class SpinButtonRenderer;
323  };
324 
325 
327 
328  class TGUI_API SpinButtonRenderer : public WidgetRenderer, public WidgetBorders
329  {
330  public:
331 
338  SpinButtonRenderer(SpinButton* spinButton) : m_spinButton{spinButton} {}
339 
340 
350  virtual void setProperty(std::string property, const std::string& value) override;
351 
352 
363  virtual void setProperty(std::string property, ObjectConverter&& value) override;
364 
365 
375  virtual ObjectConverter getProperty(std::string property) const override;
376 
377 
384  virtual std::map<std::string, ObjectConverter> getPropertyValuePairs() const override;
385 
386 
400  void setBackgroundColor(const Color& color);
401 
402 
411  void setBackgroundColorNormal(const Color& color);
412 
413 
422  void setBackgroundColorHover(const Color& color);
423 
424 
438  void setArrowColor(const Color& color);
439 
440 
449  void setArrowColorNormal(const Color& color);
450 
451 
460  void setArrowColorHover(const Color& color);
461 
462 
469  void setBorderColor(const Color& color);
470 
471 
481  void setArrowUpTexture(const Texture& texture);
482 
483 
493  void setArrowDownTexture(const Texture& texture);
494 
495 
505  void setArrowUpHoverTexture(const Texture& texture);
506 
507 
517  void setArrowDownHoverTexture(const Texture& texture);
518 
519 
530  void setSpaceBetweenArrows(float space);
531 
532 
534  // Draws the widget on the render target.
536  void draw(sf::RenderTarget& target, sf::RenderStates states) const;
537 
538 
540  private:
541 
543  // Makes a copy of the renderer
545  virtual std::shared_ptr<WidgetRenderer> clone(Widget* widget) override;
546 
547 
549  protected:
550 
551  SpinButton* m_spinButton;
552 
553  float m_spaceBetweenArrows = 2;
554 
555  Texture m_textureArrowUpNormal;
556  Texture m_textureArrowUpHover;
557  Texture m_textureArrowDownNormal;
558  Texture m_textureArrowDownHover;
559 
560  sf::Color m_backgroundColorNormal;
561  sf::Color m_backgroundColorHover;
562  sf::Color m_arrowColorNormal;
563  sf::Color m_arrowColorHover;
564 
565  sf::Color m_borderColor;
566 
567 
568  friend class SpinButton;
569 
571  };
572 
574 }
575 
577 
578 #endif // TGUI_SPIN_BUTTON_HPP
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:33
virtual Widget::Ptr clone() const override
Makes a copy of the widget if you don&#39;t know its exact type.
Definition: SpinButton.hpp:296
Implicit converter for colors.
Definition: Color.hpp:39
Definition: SpinButton.hpp:328
Class to store the position or size of a widget.
Definition: Layout.hpp:262
The parent class for every widget.
Definition: Widget.hpp:71
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
virtual void setPosition(const Layout2d &position)
set the position of the widget
Clickable widget.
Definition: ClickableWidget.hpp:55
bool getVerticalScroll() const
Returns whether the spin button lies vertical or horizontal (arrows above or next to each other)...
Definition: SpinButton.hpp:228
Spin button widget.
Definition: SpinButton.hpp:49
Parent class for every widget that has borders.
Definition: Borders.hpp:136
Implicit converter for settable properties.
Definition: ObjectConverter.hpp:42
SpinButtonRenderer(SpinButton *spinButton)
Constructor.
Definition: SpinButton.hpp:338
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:75
Definition: Texture.hpp:44
int getMaximum() const
Returns the maximum value.
Definition: SpinButton.hpp:193
std::shared_ptr< SpinButtonRenderer > getRenderer() const
Returns the renderer, which gives access to functions that determine how the widget is displayed...
Definition: SpinButton.hpp:92
std::shared_ptr< const SpinButton > ConstPtr
Shared constant widget pointer.
Definition: SpinButton.hpp:54
int getValue() const
Returns the current value.
Definition: SpinButton.hpp:207
int getMinimum() const
Returns the minimum value.
Definition: SpinButton.hpp:179
std::shared_ptr< SpinButton > Ptr
Shared widget pointer.
Definition: SpinButton.hpp:53
Base class for all renderer classes.
Definition: Widget.hpp:682