TGUI  1.0-beta
Loading...
Searching...
No Matches
SpinButton.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_SPIN_BUTTON_HPP
27#define TGUI_SPIN_BUTTON_HPP
28
29
30#include <TGUI/Renderers/SpinButtonRenderer.hpp>
31#include <TGUI/Widgets/ClickableWidget.hpp>
32#include <TGUI/Timer.hpp>
33
35
36namespace tgui
37{
41 class TGUI_API SpinButton : public ClickableWidget
42 {
43 public:
44
45 using Ptr = std::shared_ptr<SpinButton>;
46 using ConstPtr = std::shared_ptr<const SpinButton>;
47
48 static constexpr const char StaticWidgetType[] = "SpinButton";
49
50
58 SpinButton(const char* typeName = StaticWidgetType, bool initRenderer = true);
59
60
70 static SpinButton::Ptr create(float minimum = 0, float maximum = 10);
71
72
81 static SpinButton::Ptr copy(const SpinButton::ConstPtr& spinButton);
82
83
89 const SpinButtonRenderer* getSharedRenderer() const;
90
97
98
106 void setSize(const Layout2d& size) override;
107 using Widget::setSize;
108
109
119 void setMinimum(float minimum);
120
121
130 float getMinimum() const;
131
132
142 void setMaximum(float maximum);
143
144
153 float getMaximum() const;
154
155
165 void setValue(float value);
166
167
176 float getValue() const;
177
178
184 void setStep(float step);
185
186
192 float getStep() const;
193
194
201 void setVerticalScroll(bool vertical);
202
203
208 bool getVerticalScroll() const;
209
210
214 void leftMousePressed(Vector2f pos) override;
215
219 void leftMouseReleased(Vector2f pos) override;
220
224 void mouseMoved(Vector2f pos) override;
225
226
234 void draw(BackendRenderTarget& target, RenderStates states) const override;
235
236
238 protected:
239
249 Signal& getSignal(String signalName) override;
250
251
258 void rendererChanged(const String& property) override;
259
260
264 std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
265
266
270 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
271
272
274 // Returns the size of the arrows
276 Vector2f getArrowSize() const;
277
278
280 // Makes a copy of the widget
282 Widget::Ptr clone() const override;
283
284
286 private:
287
289 //
291 void callMousePressPeriodically(std::chrono::time_point<std::chrono::steady_clock> clicked);
292
293
295 public:
296
297 SignalFloat onValueChange = {"ValueChanged"};
298
299
301 protected:
302
303 // Is the spin button draw vertically (arrows on top of each other)?
304 bool m_verticalScroll = true;
305 std::chrono::time_point<std::chrono::steady_clock> m_PressedAt;
306
307 float m_minimum = 0;
308 float m_maximum = 10;
309 float m_value = 0;
310 float m_step = 1;
311
312 // On which arrow is the mouse?
313 bool m_mouseHoverOnTopArrow = false;
314 bool m_mouseDownOnTopArrow = false;
315
316 Sprite m_spriteArrowUp;
317 Sprite m_spriteArrowUpHover;
318 Sprite m_spriteArrowDown;
319 Sprite m_spriteArrowDownHover;
320
321 // Cached renderer properties
322 Borders m_bordersCached;
323 Color m_borderColorCached;
324 Color m_backgroundColorCached;
325 Color m_backgroundColorHoverCached;
326 Color m_arrowColorCached;
327 Color m_arrowColorHoverCached;
328 float m_borderBetweenArrowsCached = 0;
329 };
330
332}
333
335
336#endif // TGUI_SPIN_BUTTON_HPP
Base class for render targets.
Definition: BackendRenderTarget.hpp:48
Clickable widget.
Definition: ClickableWidget.hpp:40
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
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:58
Definition: SpinButtonRenderer.hpp:37
Spin button widget.
Definition: SpinButton.hpp:42
static SpinButton::Ptr create(float minimum=0, float maximum=10)
Creates a new spin button widget.
void setStep(float step)
Changes how much the value changes on each arrow press.
std::shared_ptr< SpinButton > Ptr
Shared widget pointer.
Definition: SpinButton.hpp:45
SpinButtonRenderer * getSharedRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
float getMaximum() const
Returns the maximum value.
bool getVerticalScroll() const
Returns whether the spin button lies horizontally or vertically.
float getStep() const
Returns the number of positions the thumb advances with each move.
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
float getValue() const
Returns the current value.
void setValue(float value)
Changes the current value.
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 setVerticalScroll(bool vertical)
Changes whether the spin button lies horizontally or vertically.
float getMinimum() const
Returns the minimum value.
std::shared_ptr< const SpinButton > ConstPtr
Shared constant widget pointer.
Definition: SpinButton.hpp:46
void setSize(const Layout2d &size) override
Changes the size of the spin button.
Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
void draw(BackendRenderTarget &target, RenderStates states) const override
Draw the widget to a render target.
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
SpinButtonRenderer * getRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
void setMaximum(float maximum)
Sets a maximum value.
void setMinimum(float minimum)
Sets a minimum value.
void rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
static SpinButton::Ptr copy(const SpinButton::ConstPtr &spinButton)
Makes a copy of another spin button.
Definition: Sprite.hpp:45
Wrapper class to store strings.
Definition: String.hpp:79
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