TGUI  0.8-dev
RangeSlider.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_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(int minimum = 0, int 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  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 setSelectionStart(int value);
184 
185 
192  int getSelectionStart() const;
193 
194 
204  void setSelectionEnd(int value);
205 
206 
213  int getSelectionEnd() const;
214 
215 
222  bool mouseOnWidget(sf::Vector2f pos) const override;
223 
227  void leftMousePressed(sf::Vector2f pos) override;
228 
232  void leftMouseReleased(sf::Vector2f pos) override;
233 
237  void mouseMoved(sf::Vector2f pos) override;
238 
242  void widgetFocused() override;
243 
247  void mouseNoLongerDown() override;
248 
249 
257  void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
258 
259 
261  protected:
262 
272  Signal& getSignal(std::string signalName) override;
273 
274 
281  void rendererChanged(const std::string& property) override;
282 
283 
285  // Returns the size without the borders
287  sf::Vector2f getInnerSize() const;
288 
289 
291  // Updates the position of the thumb based on the current value of the slider
293  void updateThumbPositions();
294 
295 
297  // Makes a copy of the widget
299  Widget::Ptr clone() const override
300  {
301  return std::make_shared<RangeSlider>(*this);
302  }
303 
304 
306  public:
307 
308  SignalRange onRangeChange = {"RangeChanged"};
309 
310 
312  protected:
313 
314  std::pair<sf::FloatRect, sf::FloatRect> m_thumbs;
315 
316  // When the mouse went down, did it go down on top of the thumb? If so, which one and where?
317  unsigned int m_mouseDownOnThumb = 0;
318  sf::Vector2f m_mouseDownOnThumbPos;
319 
320  int m_minimum = 0;
321  int m_maximum = 10;
322  int m_selectionStart = 0;
323  int m_selectionEnd = 0;
324 
325  // Is the slider drawn vertically?
326  bool m_verticalScroll = false;
327 
328  // Does the image lie vertically?
329  bool m_verticalImage = false;
330 
331  Sprite m_spriteTrack;
332  Sprite m_spriteTrackHover;
333  Sprite m_spriteThumb;
334  Sprite m_spriteThumbHover;
335 
336  // Cached renderer properties
337  Borders m_bordersCached;
338  Color m_borderColorCached;
339  Color m_borderColorHoverCached;
340  Color m_thumbColorCached;
341  Color m_thumbColorHoverCached;
342  Color m_trackColorCached;
343  Color m_trackColorHoverCached;
344  Color m_selectedTrackColorCached;
345  Color m_selectedTrackColorHoverCached;
346  };
347 
349 }
350 
352 
353 #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:272
Definition: Sprite.hpp:40
std::shared_ptr< RangeSlider > Ptr
Shared widget pointer.
Definition: RangeSlider.hpp:44
Wrapper for colors.
Definition: Color.hpp:46
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:62
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
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
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:299