TGUI  0.8-dev
Slider.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_SLIDER_HPP
27 #define TGUI_SLIDER_HPP
28 
29 
30 #include <TGUI/Widget.hpp>
31 #include <TGUI/Renderers/SliderRenderer.hpp>
32 
34 
35 namespace tgui
36 {
40  class TGUI_API Slider : public Widget
41  {
42  public:
43 
44  typedef std::shared_ptr<Slider> Ptr;
45  typedef std::shared_ptr<const Slider> ConstPtr;
46 
47 
49  // Default constructor
51  Slider();
52 
53 
63  static Slider::Ptr create(int minimum = 0, int maximum = 10);
64 
65 
74  static Slider::Ptr copy(Slider::ConstPtr slider);
75 
76 
81  SliderRenderer* getSharedRenderer();
82  const SliderRenderer* getSharedRenderer() const;
83 
89  SliderRenderer* getRenderer();
90  const SliderRenderer* getRenderer() const;
91 
92 
99  void setSize(const Layout2d& size) override;
100  using Widget::setSize;
101 
102 
111  sf::Vector2f getFullSize() const override;
112 
113 
123  sf::Vector2f getWidgetOffset() const override;
124 
125 
136  void setMinimum(int minimum);
137 
138 
147  int getMinimum() const;
148 
149 
160  void setMaximum(int maximum);
161 
162 
171  int getMaximum() const;
172 
173 
183  void setValue(int value);
184 
185 
194  int getValue() const;
195 
196 
203  bool mouseOnWidget(sf::Vector2f pos) const override;
204 
208  void leftMousePressed(sf::Vector2f pos) override;
209 
213  void leftMouseReleased(sf::Vector2f pos) override;
214 
218  void mouseMoved(sf::Vector2f pos) override;
219 
223  void mouseWheelScrolled(float delta, sf::Vector2f pos) override;
224 
228  void widgetFocused() override;
229 
233  void mouseNoLongerDown() override;
234 
235 
243  void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
244 
245 
247  protected:
248 
258  Signal& getSignal(std::string signalName) override;
259 
260 
267  void rendererChanged(const std::string& property) override;
268 
269 
271  // Returns the size without the borders
273  sf::Vector2f getInnerSize() const;
274 
275 
277  // Updates the position of the thumb based on the current value of the slider
279  void updateThumbPosition();
280 
281 
283  // Makes a copy of the widget
285  Widget::Ptr clone() const override
286  {
287  return std::make_shared<Slider>(*this);
288  }
289 
290 
292  public:
293 
294  SignalInt onValueChange = {"ValueChanged"};
295 
296 
298  protected:
299 
300  sf::FloatRect m_thumb;
301 
302  // When the mouse went down, did it go down on top of the thumb? If so, where?
303  bool m_mouseDownOnThumb = false;
304  sf::Vector2f m_mouseDownOnThumbPos;
305 
306  int m_minimum = 0;
307  int m_maximum = 10;
308  int m_value = 0;
309 
310  // Is the slider drawn vertically?
311  bool m_verticalScroll = false;
312 
313  // Does the image lie vertically?
314  bool m_verticalImage = false;
315 
316  Sprite m_spriteTrack;
317  Sprite m_spriteTrackHover;
318  Sprite m_spriteThumb;
319  Sprite m_spriteThumbHover;
320 
321  // Cached renderer properties
322  Borders m_bordersCached;
323  Color m_borderColorCached;
324  Color m_borderColorHoverCached;
325  Color m_thumbColorCached;
326  Color m_thumbColorHoverCached;
327  Color m_trackColorCached;
328  Color m_trackColorHoverCached;
329  };
330 
332 }
333 
335 
336 #endif // TGUI_SLIDER_HPP
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Definition: Sprite.hpp:40
Definition: SliderRenderer.hpp:36
Wrapper for colors.
Definition: Color.hpp:46
Class to store the position or size of a widget.
Definition: Layout.hpp:243
The parent class for every widget.
Definition: Widget.hpp:62
Widget::Ptr clone() const override
Makes a copy of the widget if you don&#39;t know its exact type.
Definition: Slider.hpp:285
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
Slider widget.
Definition: Slider.hpp:40
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:66
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:59
std::shared_ptr< Slider > Ptr
Shared widget pointer.
Definition: Slider.hpp:44
Definition: Outline.hpp:38
std::shared_ptr< const Slider > ConstPtr
Shared constant widget pointer.
Definition: Slider.hpp:45