TGUI  0.9.5
Loading...
Searching...
No Matches
Slider.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_SLIDER_HPP
27#define TGUI_SLIDER_HPP
28
29
30#include <TGUI/Widget.hpp>
31#include <TGUI/Renderers/SliderRenderer.hpp>
32
34
35namespace tgui
36{
40 class TGUI_API Slider : public Widget
41 {
42 public:
43
44 typedef std::shared_ptr<Slider> Ptr;
45 typedef std::shared_ptr<const Slider> ConstPtr;
46
47
55 Slider(const char* typeName = "Slider", bool initRenderer = true);
56
57
67 static Slider::Ptr create(float minimum = 0, float maximum = 10);
68
69
79
80
86 const SliderRenderer* getSharedRenderer() const;
87
94 const SliderRenderer* getRenderer() const;
95
96
104 void setSize(const Layout2d& size) override;
105 using Widget::setSize;
106
107
116 Vector2f getFullSize() const override;
117
118
128 Vector2f getWidgetOffset() const override;
129
130
141 void setMinimum(float minimum);
142
143
152 float getMinimum() const;
153
154
165 void setMaximum(float maximum);
166
167
176 float getMaximum() const;
177
178
188 void setValue(float value);
189
190
199 float getValue() const;
200
201
210 void setStep(float step);
211
212
218 float getStep() const;
219
220
227 void setVerticalScroll(bool vertical);
228
229
234 bool getVerticalScroll() const;
235
236
243 void setInvertedDirection(bool invertedDirection);
244
245
253
254
259 void setChangeValueOnScroll(bool changeValueOnScroll);
260
261
267
268
275 bool isMouseOnWidget(Vector2f pos) const override;
276
280 void leftMousePressed(Vector2f pos) override;
281
285 void leftMouseReleased(Vector2f pos) override;
286
290 void mouseMoved(Vector2f pos) override;
291
295 bool mouseWheelScrolled(float delta, Vector2f pos) override;
296
300 void leftMouseButtonNoLongerDown() override;
301
302
310 void draw(BackendRenderTargetBase& target, RenderStates states) const override;
311
312
314 protected:
315
325 Signal& getSignal(String signalName) override;
326
327
334 void rendererChanged(const String& property) override;
335
336
340 std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
341
342
346 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
347
348
350 // Returns the size without the borders
352 Vector2f getInnerSize() const;
353
354
356 // Updates the position of the thumb based on the current value of the slider
358 void updateThumbPosition();
359
360
362 // Makes a copy of the widget
364 Widget::Ptr clone() const override
365 {
366 return std::make_shared<Slider>(*this);
367 }
368
369
371 public:
372
373 SignalFloat onValueChange = {"ValueChanged"};
374
375
377 protected:
378
379 FloatRect m_thumb;
380
381 // When the mouse went down, did it go down on top of the thumb? If so, where?
382 bool m_mouseDownOnThumb = false;
383 Vector2f m_mouseDownOnThumbPos;
384
385 float m_minimum = 0;
386 float m_maximum = 10;
387 float m_value = 0;
388 float m_step = 1;
389
390 bool m_invertedDirection = false; // Are min and max swapped?
391 bool m_verticalScroll = false; // Is the slider drawn vertically?
392 bool m_verticalImage = false; // Does the image lie vertically?
393 bool m_changeValueOnScroll = true; // Does mouseScroll event change slider value?
394
395 Sprite m_spriteTrack;
396 Sprite m_spriteTrackHover;
397 Sprite m_spriteThumb;
398 Sprite m_spriteThumbHover;
399
400 // Cached renderer properties
401 Borders m_bordersCached;
402 Color m_borderColorCached;
403 Color m_borderColorHoverCached;
404 Color m_thumbColorCached;
405 Color m_thumbColorHoverCached;
406 Color m_trackColorCached;
407 Color m_trackColorHoverCached;
408 bool m_thumbWithinTrackCached = false;
409 };
410
412}
413
415
416#endif // TGUI_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:262
Definition Outline.hpp:39
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:58
Definition SliderRenderer.hpp:37
Slider widget.
Definition Slider.hpp:41
SliderRenderer * getRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
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.
std::shared_ptr< Slider > Ptr
Shared widget pointer.
Definition Slider.hpp:44
bool getVerticalScroll() const
Returns whether the slider lies horizontally or vertically.
Vector2f getWidgetOffset() const override
Returns the distance between the position where the widget is drawn and where the widget is placed.
bool getChangeValueOnScroll() const
Returns whether the mouse wheel can be used to change the value of the slider.
bool getInvertedDirection() const
Returns whether the side of the slider that is the minimum and maximum is inverted.
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition Slider.hpp:364
float getStep() const
Returns the number of positions the thumb advances with each move.
bool isMouseOnWidget(Vector2f pos) const override
Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget...
Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
void setVerticalScroll(bool vertical)
Changes whether the slider lies horizontally or vertically.
void setMinimum(float minimum)
Sets a minimum value.
std::shared_ptr< const Slider > ConstPtr
Shared constant widget pointer.
Definition Slider.hpp:45
Vector2f getFullSize() const override
Returns the full size of the slider.
void setStep(float step)
Changes the number of positions the thumb advances with each move.
void setChangeValueOnScroll(bool changeValueOnScroll)
Changes whether the mouse wheel can be used to change the value of the slider.
void rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
void setSize(const Layout2d &size) override
Changes the size of the slider.
static Slider::Ptr create(float minimum=0, float maximum=10)
Creates a new slider widget.
float getValue() const
Returns the current value.
float getMinimum() const
Returns the minimum value.
float getMaximum() const
Returns the maximum value.
SliderRenderer * getSharedRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
void setValue(float value)
Changes the current value.
void setInvertedDirection(bool invertedDirection)
Changes whether the side of the slider that is the minimum and maximum should be inverted.
void draw(BackendRenderTargetBase &target, RenderStates states) const override
Draw the widget to a render target.
void setMaximum(float maximum)
Sets a maximum value.
static Slider::Ptr copy(Slider::ConstPtr slider)
Makes a copy of another slider.
Definition Sprite.hpp:49
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
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:36
States used for drawing.
Definition RenderStates.hpp:39