TGUI  0.8-alpha
Slider.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_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(float minimum = 0, float 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  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 setValue(float value);
184 
185 
194  float getValue() const;
195 
196 
205  void setStep(float step);
206 
207 
213  float getStep() const;
214 
215 
222  void setInvertedDirection(bool invertedDirection);
223 
224 
231  bool getInvertedDirection() const;
232 
233 
240  bool mouseOnWidget(Vector2f pos) const override;
241 
245  void leftMousePressed(Vector2f pos) override;
246 
250  void leftMouseReleased(Vector2f pos) override;
251 
255  void mouseMoved(Vector2f pos) override;
256 
260  void mouseWheelScrolled(float delta, Vector2f pos) override;
261 
265  void mouseNoLongerDown() override;
266 
267 
275  void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
276 
277 
279  protected:
280 
290  Signal& getSignal(std::string signalName) override;
291 
292 
299  void rendererChanged(const std::string& property) override;
300 
301 
305  std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
306 
307 
311  void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
312 
313 
315  // Returns the size without the borders
317  Vector2f getInnerSize() const;
318 
319 
321  // Updates the position of the thumb based on the current value of the slider
323  void updateThumbPosition();
324 
325 
327  // Makes a copy of the widget
329  Widget::Ptr clone() const override
330  {
331  return std::make_shared<Slider>(*this);
332  }
333 
334 
336  public:
337 
338  SignalFloat onValueChange = {"ValueChanged"};
339 
340 
342  protected:
343 
344  FloatRect m_thumb;
345 
346  // When the mouse went down, did it go down on top of the thumb? If so, where?
347  bool m_mouseDownOnThumb = false;
348  Vector2f m_mouseDownOnThumbPos;
349 
350  float m_minimum = 0;
351  float m_maximum = 10;
352  float m_value = 0;
353  float m_step = 1;
354 
355  bool m_invertedDirection = false; // Are min and max swapped?
356  bool m_verticalScroll = false; // Is the slider drawn vertically?
357  bool m_verticalImage = false; // Does the image lie vertically?
358 
359  Sprite m_spriteTrack;
360  Sprite m_spriteTrackHover;
361  Sprite m_spriteThumb;
362  Sprite m_spriteThumbHover;
363 
364  // Cached renderer properties
365  Borders m_bordersCached;
366  Color m_borderColorCached;
367  Color m_borderColorHoverCached;
368  Color m_thumbColorCached;
369  Color m_thumbColorHoverCached;
370  Color m_trackColorCached;
371  Color m_trackColorHoverCached;
372  };
373 
375 }
376 
378 
379 #endif // TGUI_SLIDER_HPP
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Definition: Sprite.hpp:43
Definition: SliderRenderer.hpp:36
Wrapper for colors.
Definition: Color.hpp:47
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
Widget::Ptr clone() const override
Makes a copy of the widget if you don&#39;t know its exact type.
Definition: Slider.hpp:329
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:76
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:58
std::shared_ptr< Slider > Ptr
Shared widget pointer.
Definition: Slider.hpp:44
Definition: Outline.hpp:38
Definition: FloatRect.hpp:36
std::shared_ptr< const Slider > ConstPtr
Shared constant widget pointer.
Definition: Slider.hpp:45