TGUI  0.9.1
RangeSlider.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2021 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 
55  RangeSlider(const char* typeName = "RangeSlider", bool initRenderer = true);
56 
57 
67  static RangeSlider::Ptr create(float minimum = 0, float maximum = 10);
68 
69 
79 
80 
86  const RangeSliderRenderer* getSharedRenderer() const;
87 
94  const RangeSliderRenderer* getRenderer() const;
95 
96 
103  void setSize(const Layout2d& size) override;
104  using Widget::setSize;
105 
106 
115  Vector2f getFullSize() const override;
116 
117 
127  Vector2f getWidgetOffset() const override;
128 
129 
140  void setMinimum(float minimum);
141 
142 
151  float getMinimum() const;
152 
153 
164  void setMaximum(float maximum);
165 
166 
175  float getMaximum() const;
176 
177 
187  void setSelectionStart(float value);
188 
189 
196  float getSelectionStart() const;
197 
198 
208  void setSelectionEnd(float value);
209 
210 
217  float getSelectionEnd() const;
218 
219 
228  void setStep(float step);
229 
230 
236  float getStep() const;
237 
238 
245  bool isMouseOnWidget(Vector2f pos) const override;
246 
250  void leftMousePressed(Vector2f pos) override;
251 
255  void leftMouseReleased(Vector2f pos) override;
256 
260  void mouseMoved(Vector2f pos) override;
261 
265  void leftMouseButtonNoLongerDown() override;
266 
267 
275  void draw(BackendRenderTargetBase& target, RenderStates states) const override;
276 
277 
279  protected:
280 
290  Signal& getSignal(String signalName) override;
291 
292 
299  void rendererChanged(const 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 updateThumbPositions();
324 
325 
327  // Makes a copy of the widget
329  Widget::Ptr clone() const override
330  {
331  return std::make_shared<RangeSlider>(*this);
332  }
333 
334 
336  public:
337 
338  SignalRange onRangeChange = {"RangeChanged"};
339 
340 
342  protected:
343 
344  std::pair<FloatRect, FloatRect> m_thumbs;
345 
346  // When the mouse went down, did it go down on top of the thumb? If so, which one and where?
347  unsigned int m_mouseDownOnThumb = 0;
348  Vector2f m_mouseDownOnThumbPos;
349 
350  float m_minimum = 0;
351  float m_maximum = 10;
352  float m_selectionStart = 0;
353  float m_selectionEnd = 0;
354  float m_step = 1;
355 
356  // Is the slider drawn vertically?
357  bool m_verticalScroll = false;
358 
359  // Does the image lie vertically?
360  bool m_verticalImage = false;
361 
362  Sprite m_spriteTrack;
363  Sprite m_spriteTrackHover;
364  Sprite m_spriteThumb;
365  Sprite m_spriteThumbHover;
366  Sprite m_spriteSelectedTrack;
367  Sprite m_spriteSelectedTrackHover;
368 
369  // Cached renderer properties
370  Borders m_bordersCached;
371  Color m_borderColorCached;
372  Color m_borderColorHoverCached;
373  Color m_thumbColorCached;
374  Color m_thumbColorHoverCached;
375  Color m_trackColorCached;
376  Color m_trackColorHoverCached;
377  Color m_selectedTrackColorCached;
378  Color m_selectedTrackColorHoverCached;
379  };
380 
382 }
383 
385 
386 #endif // TGUI_RANGE_SLIDER_HPP
Base class for render targets.
Definition: BackendRenderTarget.hpp:48
Wrapper for colors.
Definition: Color.hpp:52
Class to store the position or size of a widget.
Definition: Layout.hpp:262
Definition: Outline.hpp:39
Definition: RangeSliderRenderer.hpp:37
RangeSlider widget.
Definition: RangeSlider.hpp:41
float getMinimum() const
Returns the minimum value.
Vector2f getWidgetOffset() const override
Returns the distance between the position where the widget is drawn and where the widget is placed.
float getStep() const
Returns the number of positions the thumb advances with each move.
float getSelectionEnd() const
Returns the current value where the selection ends.
void setSelectionStart(float value)
Changes the value where the selection starts.
Vector2f getFullSize() const override
Returns the full size of the slider.
void setMinimum(float minimum)
Sets a minimum value.
void setSize(const Layout2d &size) override
Changes the size of the slider.
RangeSliderRenderer * getSharedRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
float getSelectionStart() const
Returns the current value where the selection starts.
static RangeSlider::Ptr copy(RangeSlider::ConstPtr slider)
Makes a copy of another slider.
std::shared_ptr< const RangeSlider > ConstPtr
Shared constant widget pointer.
Definition: RangeSlider.hpp:45
static RangeSlider::Ptr create(float minimum=0, float maximum=10)
Creates a new slider widget.
RangeSliderRenderer * getRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
void rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
std::shared_ptr< RangeSlider > Ptr
Shared widget pointer.
Definition: RangeSlider.hpp:44
bool isMouseOnWidget(Vector2f pos) const override
Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget...
void setSelectionEnd(float value)
Changes the value where the selection ends.
void setMaximum(float maximum)
Sets a maximum value.
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition: RangeSlider.hpp:329
void draw(BackendRenderTargetBase &target, RenderStates states) const override
Draw the widget to a render target.
float getMaximum() const
Returns the maximum value.
void setStep(float step)
Changes the number of positions the thumb advances with each move.
Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
std::unique_ptr< DataIO::Node > save(SavingRenderersMap &renderers) const override
Saves the widget as a tree node in order to save it to a file.
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:58
Definition: Sprite.hpp:49
Wrapper class to store strings.
Definition: String.hpp:74
The parent class for every widget.
Definition: Widget.hpp:70
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:73
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
States used for drawing.
Definition: RenderStates.hpp:39