TGUI  0.8.6
Slider.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2019 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 
100  void setSize(const Layout2d& size) override;
101  using Widget::setSize;
102 
103 
112  Vector2f getFullSize() const override;
113 
114 
124  Vector2f getWidgetOffset() const override;
125 
126 
137  void setMinimum(float minimum);
138 
139 
148  float getMinimum() const;
149 
150 
161  void setMaximum(float maximum);
162 
163 
172  float getMaximum() const;
173 
174 
184  void setValue(float value);
185 
186 
195  float getValue() const;
196 
197 
206  void setStep(float step);
207 
208 
214  float getStep() const;
215 
216 
223  void setVerticalScroll(bool vertical);
224 
225 
230  bool getVerticalScroll() const;
231 
232 
239  void setInvertedDirection(bool invertedDirection);
240 
241 
248  bool getInvertedDirection() const;
249 
250 
255  void setChangeValueOnScroll(bool changeValueOnScroll);
256 
257 
262  bool getChangeValueOnScroll() const;
263 
264 
271  bool mouseOnWidget(Vector2f pos) const override;
272 
276  void leftMousePressed(Vector2f pos) override;
277 
281  void leftMouseReleased(Vector2f pos) override;
282 
286  void mouseMoved(Vector2f pos) override;
287 
291  bool mouseWheelScrolled(float delta, Vector2f pos) override;
292 
296  void leftMouseButtonNoLongerDown() override;
297 
298 
306  void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
307 
308 
310  protected:
311 
321  Signal& getSignal(std::string signalName) override;
322 
323 
330  void rendererChanged(const std::string& property) override;
331 
332 
336  std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
337 
338 
342  void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
343 
344 
346  // Returns the size without the borders
348  Vector2f getInnerSize() const;
349 
350 
352  // Updates the position of the thumb based on the current value of the slider
354  void updateThumbPosition();
355 
356 
358  // Makes a copy of the widget
360  Widget::Ptr clone() const override
361  {
362  return std::make_shared<Slider>(*this);
363  }
364 
365 
367  public:
368 
369  SignalFloat onValueChange = {"ValueChanged"};
370 
371 
373  protected:
374 
375  FloatRect m_thumb;
376 
377  // When the mouse went down, did it go down on top of the thumb? If so, where?
378  bool m_mouseDownOnThumb = false;
379  Vector2f m_mouseDownOnThumbPos;
380 
381  float m_minimum = 0;
382  float m_maximum = 10;
383  float m_value = 0;
384  float m_step = 1;
385 
386  bool m_invertedDirection = false; // Are min and max swapped?
387  bool m_verticalScroll = false; // Is the slider drawn vertically?
388  bool m_verticalImage = false; // Does the image lie vertically?
389  bool m_changeValueOnScroll = true; // Does mouseScroll event change slider value?
390 
391  Sprite m_spriteTrack;
392  Sprite m_spriteTrackHover;
393  Sprite m_spriteThumb;
394  Sprite m_spriteThumbHover;
395 
396  // Cached renderer properties
397  Borders m_bordersCached;
398  Color m_borderColorCached;
399  Color m_borderColorHoverCached;
400  Color m_thumbColorCached;
401  Color m_thumbColorHoverCached;
402  Color m_trackColorCached;
403  Color m_trackColorHoverCached;
404  };
405 
407 }
408 
410 
411 #endif // TGUI_SLIDER_HPP
Slider widget.
Definition: Slider.hpp:40
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:220
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:77
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Class to store the position or size of a widget.
Definition: Layout.hpp:258
Wrapper for colors.
Definition: Color.hpp:48
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition: Slider.hpp:360
Definition: Sprite.hpp:45
Definition: FloatRect.hpp:36
Definition: Vector2f.hpp:38
Definition: Outline.hpp:38
The parent class for every widget.
Definition: Widget.hpp:73
std::shared_ptr< Slider > Ptr
Shared widget pointer.
Definition: Slider.hpp:44
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
Definition: SliderRenderer.hpp:36
std::shared_ptr< const Slider > ConstPtr
Shared constant widget pointer.
Definition: Slider.hpp:45