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 {
48  class TGUI_API Slider : public Widget
49  {
50  public:
51 
52  typedef std::shared_ptr<Slider> Ptr;
53  typedef std::shared_ptr<const Slider> ConstPtr;
54 
55 
57  // Default constructor
59  Slider();
60 
61 
71  static Slider::Ptr create(int minimum = 0, int maximum = 10);
72 
73 
82  static Slider::Ptr copy(Slider::ConstPtr slider);
83 
84 
92  {
93  return aurora::downcast<SliderRenderer*>(m_renderer.get());
94  }
95 
96 
103  void setSize(const Layout2d& size) override;
105 
106 
115  virtual sf::Vector2f getFullSize() const override;
116 
117 
127  virtual sf::Vector2f getWidgetOffset() const override;
128 
129 
140  virtual void setMinimum(int minimum);
141 
142 
151  int getMinimum() const;
152 
153 
164  virtual void setMaximum(int maximum);
165 
166 
175  int getMaximum() const;
176 
177 
187  virtual void setValue(int value);
188 
189 
198  int getValue() const;
199 
200 
204  virtual bool mouseOnWidget(sf::Vector2f pos) const override;
205 
209  virtual void leftMousePressed(sf::Vector2f pos) override;
210 
214  virtual void leftMouseReleased(sf::Vector2f pos) override;
215 
219  virtual void mouseMoved(sf::Vector2f pos) override;
220 
224  virtual void mouseWheelScrolled(float delta, int x, int y) override;
225 
229  virtual void widgetFocused() override;
230 
234  virtual void mouseNoLongerDown() override;
235 
236 
244  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
245 
246 
248  protected:
249 
256  virtual void rendererChanged(const std::string& property) override;
257 
258 
260  // Returns the size without the borders
262  sf::Vector2f getInnerSize() const;
263 
264 
266  // Updates the position of the thumb based on the current value of the slider
268  void updateThumbPosition();
269 
270 
272  // Makes a copy of the widget
274  virtual Widget::Ptr clone() const override
275  {
276  return std::make_shared<Slider>(*this);
277  }
278 
279 
281  protected:
282 
283  sf::FloatRect m_thumb;
284 
285  // When the mouse went down, did it go down on top of the thumb? If so, where?
286  bool m_mouseDownOnThumb = false;
287  sf::Vector2f m_mouseDownOnThumbPos;
288 
289  int m_minimum = 0;
290  int m_maximum = 10;
291  int m_value = 0;
292 
293  // Is the slider drawn vertically?
294  bool m_verticalScroll = false;
295 
296  // Does the image lie vertically?
297  bool m_verticalImage = false;
298 
299  Sprite m_spriteTrack;
300  Sprite m_spriteTrackHover;
301  Sprite m_spriteThumb;
302  Sprite m_spriteThumbHover;
303 
304  // Cached renderer properties
305  Borders m_bordersCached;
306  Color m_borderColorCached;
307  Color m_borderColorHoverCached;
308  Color m_thumbColorCached;
309  Color m_thumbColorHoverCached;
310  Color m_trackColorCached;
311  Color m_trackColorHoverCached;
312  };
313 
315 }
316 
318 
319 #endif // TGUI_SLIDER_HPP
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:33
Definition: Sprite.hpp:40
Definition: SliderRenderer.hpp:36
Wrapper for colors.
Definition: Color.hpp:46
SliderRenderer * getRenderer() const
Returns the renderer, which gives access to functions that determine how the widget is displayed...
Definition: Slider.hpp:91
Class to store the position or size of a widget.
Definition: Layout.hpp:263
The parent class for every widget.
Definition: Widget.hpp:72
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
Slider widget.
Definition: Slider.hpp:48
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:76
std::shared_ptr< Slider > Ptr
Shared widget pointer.
Definition: Slider.hpp:52
Definition: Outline.hpp:37
virtual Widget::Ptr clone() const override
Makes a copy of the widget if you don&#39;t know its exact type.
Definition: Slider.hpp:274
std::shared_ptr< const Slider > ConstPtr
Shared constant widget pointer.
Definition: Slider.hpp:53