TGUI  1.3-dev
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
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
35TGUI_MODULE_EXPORT namespace tgui
36{
40 class TGUI_API RangeSlider : public Widget
41 {
42 public:
43
44 using Ptr = std::shared_ptr<RangeSlider>;
45 using ConstPtr = std::shared_ptr<const RangeSlider>;
46
47 static constexpr const char StaticWidgetType[] = "RangeSlider";
48
49
57 RangeSlider(const char* typeName = StaticWidgetType, bool initRenderer = true);
58
59
69 TGUI_NODISCARD static RangeSlider::Ptr create(float minimum = 0, float maximum = 10);
70
71
80 TGUI_NODISCARD static RangeSlider::Ptr copy(const RangeSlider::ConstPtr& slider);
81
82
87 TGUI_NODISCARD RangeSliderRenderer* getSharedRenderer() override;
88 TGUI_NODISCARD const RangeSliderRenderer* getSharedRenderer() const override;
89
95 TGUI_NODISCARD RangeSliderRenderer* getRenderer() override;
96
97
104 void setSize(const Layout2d& size) override;
105 using Widget::setSize;
106
107
116 TGUI_NODISCARD Vector2f getFullSize() const override;
117
118
128 TGUI_NODISCARD Vector2f getWidgetOffset() const override;
129
130
141 void setMinimum(float minimum);
142
143
152 TGUI_NODISCARD float getMinimum() const;
153
154
165 void setMaximum(float maximum);
166
167
176 TGUI_NODISCARD float getMaximum() const;
177
178
188 void setSelectionStart(float value);
189
190
197 TGUI_NODISCARD float getSelectionStart() const;
198
199
209 void setSelectionEnd(float value);
210
211
218 TGUI_NODISCARD float getSelectionEnd() const;
219
220
229 void setStep(float step);
230
231
237 TGUI_NODISCARD float getStep() const;
238
239
246 TGUI_NODISCARD bool isMouseOnWidget(Vector2f pos) const override;
247
251 bool leftMousePressed(Vector2f pos) override;
252
256 void leftMouseReleased(Vector2f pos) override;
257
261 void mouseMoved(Vector2f pos) override;
262
266 void leftMouseButtonNoLongerDown() override;
267
268
276 void draw(BackendRenderTarget& target, RenderStates states) const override;
277
278
280 protected:
281
291 TGUI_NODISCARD Signal& getSignal(String signalName) override;
292
293
300 void rendererChanged(const String& property) override;
301
302
306 TGUI_NODISCARD std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
307
308
312 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
313
314
316 // Returns the size without the borders
318 TGUI_NODISCARD Vector2f getInnerSize() const;
319
320
322 // Updates the position of the thumb based on the current value of the slider
324 void updateThumbPositions();
325
326
328 // Makes a copy of the widget
330 TGUI_NODISCARD Widget::Ptr clone() const override;
331
332
334 public:
335
336 SignalRange onRangeChange = {"RangeChanged"};
337
338
340 protected:
341
342 std::pair<FloatRect, FloatRect> m_thumbs;
343
344 // When the mouse went down, did it go down on top of the thumb? If so, which one and where?
345 unsigned int m_mouseDownOnThumb = 0;
346 Vector2f m_mouseDownOnThumbPos;
347
348 float m_minimum = 0;
349 float m_maximum = 10;
350 float m_selectionStart = 0;
351 float m_selectionEnd = 0;
352 float m_step = 1;
353
354 // Is the slider drawn vertically?
355 bool m_verticalScroll = false;
356
357 // Does the image lie vertically?
358 bool m_verticalImage = false;
359
360 Sprite m_spriteTrack;
361 Sprite m_spriteTrackHover;
362 Sprite m_spriteThumb;
363 Sprite m_spriteThumbHover;
364 Sprite m_spriteSelectedTrack;
365 Sprite m_spriteSelectedTrackHover;
366
367 // Cached renderer properties
368 Borders m_bordersCached;
369 Color m_borderColorCached;
370 Color m_borderColorHoverCached;
371 Color m_thumbColorCached;
372 Color m_thumbColorHoverCached;
373 Color m_trackColorCached;
374 Color m_trackColorHoverCached;
375 Color m_selectedTrackColorCached;
376 Color m_selectedTrackColorHoverCached;
377 };
378
380}
381
383
384#endif // TGUI_RANGE_SLIDER_HPP
Base class for render targets.
Definition BackendRenderTarget.hpp:48
Wrapper for colors.
Definition Color.hpp:72
Class to store the position or size of a widget.
Definition Layout.hpp:305
Definition Outline.hpp:39
Definition RangeSliderRenderer.hpp:37
RangeSlider widget.
Definition RangeSlider.hpp:41
TGUI_NODISCARD float getSelectionStart() const
Returns the current value where the selection starts.
TGUI_NODISCARD Vector2f getFullSize() const override
Returns the full size of the slider.
bool leftMousePressed(Vector2f pos) override
Called by the parent when the left mouse button goes down on top of the widget.
TGUI_NODISCARD 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:44
TGUI_NODISCARD Vector2f getWidgetOffset() const override
Returns the distance between the position where the widget is drawn and where the widget is placed.
TGUI_NODISCARD RangeSliderRenderer * getRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
void setMinimum(float minimum)
Sets a minimum value.
void setSize(const Layout2d &size) override
Changes the size of the slider.
TGUI_NODISCARD 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 rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
TGUI_NODISCARD RangeSliderRenderer * getSharedRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
static TGUI_NODISCARD RangeSlider::Ptr create(float minimum=0, float maximum=10)
Creates a new slider widget.
void setSelectionEnd(float value)
Changes the value where the selection ends.
void setMaximum(float maximum)
Sets a maximum value.
TGUI_NODISCARD float getMinimum() const
Returns the minimum value.
TGUI_NODISCARD Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
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.
TGUI_NODISCARD float getStep() const
Returns the number of positions the thumb advances with each move.
TGUI_NODISCARD Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
void setStep(float step)
Changes the number of positions the thumb advances with each move.
static TGUI_NODISCARD RangeSlider::Ptr copy(const RangeSlider::ConstPtr &slider)
Makes a copy of another slider.
TGUI_NODISCARD float getMaximum() const
Returns the maximum value.
TGUI_NODISCARD bool isMouseOnWidget(Vector2f pos) const override
Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget...
std::shared_ptr< const RangeSlider > ConstPtr
Shared constant widget pointer.
Definition RangeSlider.hpp:45
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:62
Definition Sprite.hpp:48
Wrapper class to store strings.
Definition String.hpp:101
The parent class for every widget.
Definition Widget.hpp:84
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition Widget.hpp:87
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:39
States used for drawing.
Definition RenderStates.hpp:39