TGUI  1.6.1
Loading...
Searching...
No Matches
RangeSlider.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2024 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#ifndef TGUI_RANGE_SLIDER_HPP
26#define TGUI_RANGE_SLIDER_HPP
27
28#include <TGUI/Widget.hpp>
29#include <TGUI/Renderers/RangeSliderRenderer.hpp>
30
32
33TGUI_MODULE_EXPORT namespace tgui
34{
38 class TGUI_API RangeSlider : public Widget
39 {
40 public:
41
42 using Ptr = std::shared_ptr<RangeSlider>;
43 using ConstPtr = std::shared_ptr<const RangeSlider>;
44
45 static constexpr const char StaticWidgetType[] = "RangeSlider";
46
54 RangeSlider(const char* typeName = StaticWidgetType, bool initRenderer = true);
55
64 TGUI_NODISCARD static RangeSlider::Ptr create(float minimum = 0, float maximum = 10);
65
73 TGUI_NODISCARD static RangeSlider::Ptr copy(const RangeSlider::ConstPtr& slider);
74
79 TGUI_NODISCARD RangeSliderRenderer* getSharedRenderer() override;
80 TGUI_NODISCARD const RangeSliderRenderer* getSharedRenderer() const override;
81
87 TGUI_NODISCARD RangeSliderRenderer* getRenderer() override;
88
94 void setSize(const Layout2d& size) override;
95 using Widget::setSize;
96
104 TGUI_NODISCARD Vector2f getFullSize() const override;
105
114 TGUI_NODISCARD Vector2f getWidgetOffset() const override;
115
125 void setMinimum(float minimum);
126
134 TGUI_NODISCARD float getMinimum() const;
135
145 void setMaximum(float maximum);
146
154 TGUI_NODISCARD float getMaximum() const;
155
164 void setSelectionStart(float value);
165
171 TGUI_NODISCARD float getSelectionStart() const;
172
181 void setSelectionEnd(float value);
182
188 TGUI_NODISCARD float getSelectionEnd() const;
189
198 void setStep(float step);
199
205 TGUI_NODISCARD float getStep() const;
206
212 TGUI_NODISCARD bool isMouseOnWidget(Vector2f pos) const override;
213
217 bool leftMousePressed(Vector2f pos) override;
218
222 void leftMouseReleased(Vector2f pos) override;
223
227 void mouseMoved(Vector2f pos) override;
228
232 void leftMouseButtonNoLongerDown() override;
233
240 void draw(BackendRenderTarget& target, RenderStates states) const override;
241
243 protected:
244
254 TGUI_NODISCARD Signal& getSignal(String signalName) override;
255
261 void rendererChanged(const String& property) override;
262
266 TGUI_NODISCARD std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
267
271 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
272
274 // Returns the size without the borders
276 TGUI_NODISCARD Vector2f getInnerSize() const;
277
279 // Updates the position of the thumb based on the current value of the slider
281 void updateThumbPositions();
282
284 // Makes a copy of the widget
286 TGUI_NODISCARD Widget::Ptr clone() const override;
287
289 public:
290
291 SignalRange onRangeChange = {"RangeChanged"};
292
294 protected:
295
296 std::pair<FloatRect, FloatRect> m_thumbs;
297
298 // When the mouse went down, did it go down on top of the thumb? If so, which one and where?
299 unsigned int m_mouseDownOnThumb = 0;
300 Vector2f m_mouseDownOnThumbPos;
301
302 float m_minimum = 0;
303 float m_maximum = 10;
304 float m_selectionStart = 0;
305 float m_selectionEnd = 0;
306 float m_step = 1;
307
308 Orientation m_orientation = Orientation::Horizontal; // Is the slider drawn horizontally or vertically?
309 Orientation m_imageOrientation = Orientation::Horizontal; // Does the loaded image lie horizontally or vertically?
310
311 Sprite m_spriteTrack;
312 Sprite m_spriteTrackHover;
313 Sprite m_spriteThumb;
314 Sprite m_spriteThumbHover;
315 Sprite m_spriteSelectedTrack;
316 Sprite m_spriteSelectedTrackHover;
317
318 // Cached renderer properties
319 Borders m_bordersCached;
320 Color m_borderColorCached;
321 Color m_borderColorHoverCached;
322 Color m_thumbColorCached;
323 Color m_thumbColorHoverCached;
324 Color m_trackColorCached;
325 Color m_trackColorHoverCached;
326 Color m_selectedTrackColorCached;
327 Color m_selectedTrackColorHoverCached;
328 };
329
331}
332
334
335#endif // TGUI_RANGE_SLIDER_HPP
Base class for render targets.
Definition BackendRenderTarget.hpp:46
Wrapper for colors.
Definition Color.hpp:73
Class to store the position or size of a widget.
Definition Layout.hpp:323
Definition Outline.hpp:38
Definition RangeSliderRenderer.hpp:35
RangeSlider widget.
Definition RangeSlider.hpp:39
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.
bool leftMousePressed(Vector2f pos) override
Called by the parent when the left mouse button goes down on top of the widget.
float getSelectionEnd() const
Returns the current value where the selection ends.
void setSelectionStart(float value)
Changes the value where the selection starts.
std::shared_ptr< RangeSlider > Ptr
Shared widget pointer.
Definition RangeSlider.hpp:42
RangeSliderRenderer * getSharedRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
Vector2f getFullSize() const override
Returns the full size of the slider.
static RangeSlider::Ptr copy(const RangeSlider::ConstPtr &slider)
Makes a copy of another 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.
static RangeSlider::Ptr create(float minimum=0, float maximum=10)
Creates a new slider widget.
Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
void rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
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.
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 draw(BackendRenderTarget &target, RenderStates states) const override
Draw the widget to a render target.
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.
float getMaximum() const
Returns the maximum value.
void setStep(float step)
Changes the number of positions the thumb advances with each move.
RangeSliderRenderer * getRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
std::shared_ptr< const RangeSlider > ConstPtr
Shared constant widget pointer.
Definition RangeSlider.hpp:43
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:61
Definition Sprite.hpp:47
Wrapper class to store strings.
Definition String.hpp:96
The parent class for every widget.
Definition Widget.hpp:83
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition Widget.hpp:86
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38
Orientation
Orientation of the object.
Definition Layout.hpp:52
States used for drawing.
Definition RenderStates.hpp:38