TGUI  0.8.9
RangeSlider.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2020 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
35namespace 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
49 // Default constructor
52
53
63 static RangeSlider::Ptr create(float minimum = 0, float maximum = 10);
64
65
75
76
82 const RangeSliderRenderer* getSharedRenderer() const;
83
90 const RangeSliderRenderer* 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 setSelectionStart(float value);
184
185
192 float getSelectionStart() const;
193
194
204 void setSelectionEnd(float value);
205
206
213 float getSelectionEnd() const;
214
215
224 void setStep(float step);
225
226
232 float getStep() const;
233
234
241 bool mouseOnWidget(Vector2f pos) const override;
242
246 void leftMousePressed(Vector2f pos) override;
247
251 void leftMouseReleased(Vector2f pos) override;
252
256 void mouseMoved(Vector2f pos) override;
257
261 void leftMouseButtonNoLongerDown() override;
262
263
271 void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
272
273
275 protected:
276
286 Signal& getSignal(std::string signalName) override;
287
288
295 void rendererChanged(const std::string& property) override;
296
297
301 std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
302
303
307 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
308
309
311 // Returns the size without the borders
313 Vector2f getInnerSize() const;
314
315
317 // Updates the position of the thumb based on the current value of the slider
319 void updateThumbPositions();
320
321
323 // Makes a copy of the widget
325 Widget::Ptr clone() const override
326 {
327 return std::make_shared<RangeSlider>(*this);
328 }
329
330
332 public:
333
334 SignalRange onRangeChange = {"RangeChanged"};
335
336
338 protected:
339
340 std::pair<FloatRect, FloatRect> m_thumbs;
341
342 // When the mouse went down, did it go down on top of the thumb? If so, which one and where?
343 unsigned int m_mouseDownOnThumb = 0;
344 Vector2f m_mouseDownOnThumbPos;
345
346 float m_minimum = 0;
347 float m_maximum = 10;
348 float m_selectionStart = 0;
349 float m_selectionEnd = 0;
350 float m_step = 1;
351
352 // Is the slider drawn vertically?
353 bool m_verticalScroll = false;
354
355 // Does the image lie vertically?
356 bool m_verticalImage = false;
357
358 Sprite m_spriteTrack;
359 Sprite m_spriteTrackHover;
360 Sprite m_spriteThumb;
361 Sprite m_spriteThumbHover;
362
363 // Cached renderer properties
364 Borders m_bordersCached;
365 Color m_borderColorCached;
366 Color m_borderColorHoverCached;
367 Color m_thumbColorCached;
368 Color m_thumbColorHoverCached;
369 Color m_trackColorCached;
370 Color m_trackColorHoverCached;
371 Color m_selectedTrackColorCached;
372 Color m_selectedTrackColorHoverCached;
373 };
374
376}
377
379
380#endif // TGUI_RANGE_SLIDER_HPP
Wrapper for colors.
Definition: Color.hpp:49
Class to store the position or size of a widget.
Definition: Layout.hpp:260
Definition: Outline.hpp:39
Definition: RangeSliderRenderer.hpp:37
RangeSlider widget.
Definition: RangeSlider.hpp:41
void draw(sf::RenderTarget &target, sf::RenderStates states) const override
Draw the widget to a render target.
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.
void rendererChanged(const std::string &property) override
Function called when one of the properties of the renderer is changed.
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.
float getSelectionStart() const
Returns the current value where the selection starts.
RangeSliderRenderer * getSharedRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
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.
std::shared_ptr< RangeSlider > Ptr
Shared widget pointer.
Definition: RangeSlider.hpp:44
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.
void setSelectionEnd(float value)
Changes the value where the selection ends.
bool mouseOnWidget(Vector2f pos) const override
Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget...
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:325
RangeSliderRenderer * getRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
Signal & getSignal(std::string signalName) override
Retrieves a signal based on its name.
float getMaximum() const
Returns the maximum value.
void setStep(float step)
Changes the number of positions the thumb advances with each move.
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:452
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:231
Definition: Sprite.hpp:46
Definition: Vector2f.hpp:39
The parent class for every widget.
Definition: Widget.hpp:74
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:77
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:37