TGUI  0.7.4
Slider.hpp
1 //
3 // TGUI - Texus's 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 
33 
34 namespace tgui
35 {
36  class SliderRenderer;
37 
49  class TGUI_API Slider : public Widget
50  {
51  public:
52 
53  typedef std::shared_ptr<Slider> Ptr;
54  typedef std::shared_ptr<const Slider> ConstPtr;
55 
56 
58  // Default constructor
60  Slider();
61 
62 
72  static Slider::Ptr create(int minimum = 0, int maximum = 10);
73 
74 
83  static Slider::Ptr copy(Slider::ConstPtr slider);
84 
85 
92  std::shared_ptr<SliderRenderer> getRenderer() const
93  {
94  return std::static_pointer_cast<SliderRenderer>(m_renderer);
95  }
96 
97 
110  virtual void setPosition(const Layout2d& position) override;
112 
113 
120  void setSize(const Layout2d& size) override;
122 
123 
132  virtual sf::Vector2f getFullSize() const override;
133 
134 
145  virtual void setMinimum(int minimum);
146 
147 
158  virtual void setMaximum(int maximum);
159 
160 
170  virtual void setValue(int value);
171 
172 
181  int getMinimum() const
182  {
183  return m_minimum;
184  }
185 
186 
195  int getMaximum() const
196  {
197  return m_maximum;
198  }
199 
200 
209  int getValue() const
210  {
211  return m_value;
212  }
213 
214 
221  virtual void setOpacity(float opacity) override;
222 
223 
232  virtual sf::Vector2f getWidgetOffset() const override;
233 
234 
238  virtual bool mouseOnWidget(float x, float y) const override;
239 
243  virtual void leftMousePressed(float x, float y) override;
244 
248  virtual void leftMouseReleased(float x, float y) override;
249 
253  virtual void mouseMoved(float x, float y) override;
254 
258  virtual void mouseWheelMoved(int delta, int x, int y) override;
259 
263  virtual void widgetFocused() override;
264 
268  virtual void mouseNoLongerDown() override;
269 
270 
272  protected:
273 
286  virtual void reload(const std::string& primary = "", const std::string& secondary = "", bool force = false) override;
287 
288 
290  // Makes a copy of the widget
292  virtual Widget::Ptr clone() const override
293  {
294  return std::make_shared<Slider>(*this);
295  }
296 
297 
299  // Draws the widget on the render target.
301  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
302 
303 
305  protected:
306 
307  sf::FloatRect m_thumb;
308 
309  // When the mouse went down, did it go down on top of the thumb? If so, where?
310  bool m_mouseDownOnThumb = false;
311  sf::Vector2f m_mouseDownOnThumbPos;
312 
313  int m_minimum = 0;
314  int m_maximum = 10;
315  int m_value = 0;
316 
317  // Is the slider drawn vertically?
318  bool m_verticalScroll = false;
319 
320  // Does the image lie vertically?
321  bool m_verticalImage = false;
322 
323 
324  friend class SliderRenderer;
325  };
326 
327 
329 
330  class TGUI_API SliderRenderer : public WidgetRenderer, public WidgetBorders
331  {
332  public:
333 
340  SliderRenderer(Slider* slider) : m_slider{slider} {}
341 
342 
352  virtual void setProperty(std::string property, const std::string& value) override;
353 
354 
365  virtual void setProperty(std::string property, ObjectConverter&& value) override;
366 
367 
377  virtual ObjectConverter getProperty(std::string property) const override;
378 
379 
386  virtual std::map<std::string, ObjectConverter> getPropertyValuePairs() const override;
387 
388 
402  void setTrackColor(const Color& color);
403 
404 
413  void setTrackColorNormal(const Color& color);
414 
415 
424  void setTrackColorHover(const Color& color);
425 
426 
440  void setThumbColor(const Color& color);
441 
442 
451  void setThumbColorNormal(const Color& color);
452 
453 
462  void setThumbColorHover(const Color& color);
463 
464 
471  void setBorderColor(const Color& color);
472 
473 
483  void setTrackTexture(const Texture& texture);
484 
485 
495  void setTrackHoverTexture(const Texture& texture);
496 
497 
507  void setThumbTexture(const Texture& texture);
508 
509 
519  void setThumbHoverTexture(const Texture& texture);
520 
521 
523  // Draws the widget on the render target.
525  void draw(sf::RenderTarget& target, sf::RenderStates states) const;
526 
527 
529  private:
530 
532  // Makes a copy of the renderer
534  virtual std::shared_ptr<WidgetRenderer> clone(Widget* widget) override;
535 
536 
538  protected:
539 
540  Slider* m_slider;
541 
542  Texture m_textureTrackNormal;
543  Texture m_textureTrackHover;
544  Texture m_textureThumbNormal;
545  Texture m_textureThumbHover;
546 
547  sf::Color m_trackColorNormal;
548  sf::Color m_trackColorHover;
549 
550  sf::Color m_thumbColorNormal;
551  sf::Color m_thumbColorHover;
552 
553  sf::Color m_borderColor;
554 
555  friend class Slider;
556 
558  };
559 
561 }
562 
564 
565 #endif // TGUI_SLIDER_HPP
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:33
Definition: Slider.hpp:330
Implicit converter for colors.
Definition: Color.hpp:39
std::shared_ptr< SliderRenderer > getRenderer() const
Returns the renderer, which gives access to functions that determine how the widget is displayed...
Definition: Slider.hpp:92
Class to store the position or size of a widget.
Definition: Layout.hpp:262
The parent class for every widget.
Definition: Widget.hpp:71
int getValue() const
Returns the current value.
Definition: Slider.hpp:209
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
int getMinimum() const
Returns the minimum value.
Definition: Slider.hpp:181
virtual void setPosition(const Layout2d &position)
set the position of the widget
Slider widget.
Definition: Slider.hpp:49
Parent class for every widget that has borders.
Definition: Borders.hpp:136
Implicit converter for settable properties.
Definition: ObjectConverter.hpp:42
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:75
Definition: Texture.hpp:44
std::shared_ptr< Slider > Ptr
Shared widget pointer.
Definition: Slider.hpp:53
int getMaximum() const
Returns the maximum value.
Definition: Slider.hpp:195
SliderRenderer(Slider *slider)
Constructor.
Definition: Slider.hpp:340
virtual Widget::Ptr clone() const override
Makes a copy of the widget if you don&#39;t know its exact type.
Definition: Slider.hpp:292
Base class for all renderer classes.
Definition: Widget.hpp:682
std::shared_ptr< const Slider > ConstPtr
Shared constant widget pointer.
Definition: Slider.hpp:54