TGUI  0.8.0
RangeSlider.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_RANGE_SLIDER_HPP
27 #define TGUI_RANGE_SLIDER_HPP
28 
29 
30 #include <TGUI/Widget.hpp>
31 #include <TGUI/Renderers/RangeSliderRenderer.hpp>
32 
34 
35 namespace tgui
36 {
40  class TGUI_API RangeSlider : public Widget
41  {
42  public:
43 
44  typedef std::shared_ptr<RangeSlider> Ptr;
45  typedef std::shared_ptr<const RangeSlider> ConstPtr;
46 
47 
49  // Default constructor
51  RangeSlider();
52 
53 
63  static RangeSlider::Ptr create(float minimum = 0, float maximum = 10);
64 
65 
74  static RangeSlider::Ptr copy(RangeSlider::ConstPtr slider);
75 
76 
81  RangeSliderRenderer* getSharedRenderer();
82  const RangeSliderRenderer* getSharedRenderer() const;
83 
89  RangeSliderRenderer* getRenderer();
90  const RangeSliderRenderer* getRenderer() const;
91 
92 
99  void setSize(const Layout2d& size) override;
100  using Widget::setSize;
101 
102 
111  Vector2f getFullSize() const override;
112 
113 
123  Vector2f getWidgetOffset() const override;
124 
125 
136  void setMinimum(float minimum);
137 
138 
147  float getMinimum() const;
148 
149 
160  void setMaximum(float maximum);
161 
162 
171  float getMaximum() const;
172 
173 
183  void setSelectionStart(float value);
184 
185 
192  float getSelectionStart() const;
193 
194 
204  void setSelectionEnd(float value);
205 
206 
213  float getSelectionEnd() const;
214 
215 
224  void setStep(float step);
225 
226 
232  float getStep() const;
233 
234 
241  bool mouseOnWidget(Vector2f pos) const override;
242 
246  void leftMousePressed(Vector2f pos) override;
247 
251  void leftMouseReleased(Vector2f pos) override;
252 
256  void mouseMoved(Vector2f pos) override;
257 
261  void mouseNoLongerDown() override;
262 
263 
271  void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
272 
273 
275  protected:
276 
286  Signal& getSignal(std::string signalName) override;
287 
288 
295  void rendererChanged(const std::string& property) override;
296 
297 
301  std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
302 
303 
307  void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
308 
309 
311  // Returns the size without the borders
313  Vector2f getInnerSize() const;
314 
315 
317  // Updates the position of the thumb based on the current value of the slider
319  void updateThumbPositions();
320 
321 
323  // Makes a copy of the widget
325  Widget::Ptr clone() const override
326  {
327  return std::make_shared<RangeSlider>(*this);
328  }
329 
330 
332  public:
333 
334  SignalRange onRangeChange = {"RangeChanged"};
335 
336 
338  protected:
339 
340  std::pair<FloatRect, FloatRect> m_thumbs;
341 
342  // When the mouse went down, did it go down on top of the thumb? If so, which one and where?
343  unsigned int m_mouseDownOnThumb = 0;
344  Vector2f m_mouseDownOnThumbPos;
345 
346  float m_minimum = 0;
347  float m_maximum = 10;
348  float m_selectionStart = 0;
349  float m_selectionEnd = 0;
350  float m_step = 1;
351 
352  // Is the slider drawn vertically?
353  bool m_verticalScroll = false;
354 
355  // Does the image lie vertically?
356  bool m_verticalImage = false;
357 
358  Sprite m_spriteTrack;
359  Sprite m_spriteTrackHover;
360  Sprite m_spriteThumb;
361  Sprite m_spriteThumbHover;
362 
363  // Cached renderer properties
364  Borders m_bordersCached;
365  Color m_borderColorCached;
366  Color m_borderColorHoverCached;
367  Color m_thumbColorCached;
368  Color m_thumbColorHoverCached;
369  Color m_trackColorCached;
370  Color m_trackColorHoverCached;
371  Color m_selectedTrackColorCached;
372  Color m_selectedTrackColorHoverCached;
373  };
374 
376 }
377 
379 
380 #endif // TGUI_RANGE_SLIDER_HPP
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:274
Definition: Sprite.hpp:43
std::shared_ptr< RangeSlider > Ptr
Shared widget pointer.
Definition: RangeSlider.hpp:44
Wrapper for colors.
Definition: Color.hpp:47
std::shared_ptr< const RangeSlider > ConstPtr
Shared constant widget pointer.
Definition: RangeSlider.hpp:45
Class to store the position or size of a widget.
Definition: Layout.hpp:243
The parent class for every widget.
Definition: Widget.hpp:72
Definition: Vector2f.hpp:37
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
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:59
RangeSlider widget.
Definition: RangeSlider.hpp:40
Definition: Outline.hpp:38
Definition: RangeSliderRenderer.hpp:36
Widget::Ptr clone() const override
Makes a copy of the widget if you don&#39;t know its exact type.
Definition: RangeSlider.hpp:325