TGUI  1.0-alpha
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
95
102 void setSize(const Layout2d& size) override;
103 using Widget::setSize;
104
105
114 Vector2f getFullSize() const override;
115
116
126 Vector2f getWidgetOffset() const override;
127
128
139 void setMinimum(float minimum);
140
141
150 float getMinimum() const;
151
152
163 void setMaximum(float maximum);
164
165
174 float getMaximum() const;
175
176
186 void setSelectionStart(float value);
187
188
195 float getSelectionStart() const;
196
197
207 void setSelectionEnd(float value);
208
209
216 float getSelectionEnd() const;
217
218
227 void setStep(float step);
228
229
235 float getStep() const;
236
237
244 bool isMouseOnWidget(Vector2f pos) const override;
245
249 void leftMousePressed(Vector2f pos) override;
250
254 void leftMouseReleased(Vector2f pos) override;
255
259 void mouseMoved(Vector2f pos) override;
260
264 void leftMouseButtonNoLongerDown() override;
265
266
274 void draw(BackendRenderTarget& target, RenderStates states) const override;
275
276
278 protected:
279
289 Signal& getSignal(String signalName) override;
290
291
298 void rendererChanged(const String& property) override;
299
300
304 std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
305
306
310 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
311
312
314 // Returns the size without the borders
316 Vector2f getInnerSize() const;
317
318
320 // Updates the position of the thumb based on the current value of the slider
322 void updateThumbPositions();
323
324
326 // Makes a copy of the widget
328 Widget::Ptr clone() const override;
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 Sprite m_spriteSelectedTrack;
363 Sprite m_spriteSelectedTrackHover;
364
365 // Cached renderer properties
366 Borders m_bordersCached;
367 Color m_borderColorCached;
368 Color m_borderColorHoverCached;
369 Color m_thumbColorCached;
370 Color m_thumbColorHoverCached;
371 Color m_trackColorCached;
372 Color m_trackColorHoverCached;
373 Color m_selectedTrackColorCached;
374 Color m_selectedTrackColorHoverCached;
375 };
376
378}
379
381
382#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