TGUI  0.10-beta
RangeSlider.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2022 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
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(BackendRenderTarget& 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
333 public:
334
335 SignalRange onRangeChange = {"RangeChanged"};
336
337
339 protected:
340
341 std::pair<FloatRect, FloatRect> m_thumbs;
342
343 // When the mouse went down, did it go down on top of the thumb? If so, which one and where?
344 unsigned int m_mouseDownOnThumb = 0;
345 Vector2f m_mouseDownOnThumbPos;
346
347 float m_minimum = 0;
348 float m_maximum = 10;
349 float m_selectionStart = 0;
350 float m_selectionEnd = 0;
351 float m_step = 1;
352
353 // Is the slider drawn vertically?
354 bool m_verticalScroll = false;
355
356 // Does the image lie vertically?
357 bool m_verticalImage = false;
358
359 Sprite m_spriteTrack;
360 Sprite m_spriteTrackHover;
361 Sprite m_spriteThumb;
362 Sprite m_spriteThumbHover;
363 Sprite m_spriteSelectedTrack;
364 Sprite m_spriteSelectedTrackHover;
365
366 // Cached renderer properties
367 Borders m_bordersCached;
368 Color m_borderColorCached;
369 Color m_borderColorHoverCached;
370 Color m_thumbColorCached;
371 Color m_thumbColorHoverCached;
372 Color m_trackColorCached;
373 Color m_trackColorHoverCached;
374 Color m_selectedTrackColorCached;
375 Color m_selectedTrackColorHoverCached;
376 };
377
379}
380
382
383#endif // TGUI_RANGE_SLIDER_HPP
Base class for render targets.
Definition: BackendRenderTarget.hpp:48
Wrapper for colors.
Definition: Color.hpp:63
Class to store the position or size of a widget.
Definition: Layout.hpp:284
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.
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.
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::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.
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.
RangeSliderRenderer * getRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
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:58
Definition: Sprite.hpp:45
Wrapper class to store strings.
Definition: String.hpp:79
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