TGUI  0.9.5
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 typedef std::shared_ptr<SpinButton> Ptr;
46 typedef std::shared_ptr<const SpinButton> ConstPtr;
47
48
56 SpinButton(const char* typeName = "SpinButton", bool initRenderer = true);
57
58
68 static SpinButton::Ptr create(float minimum = 0, float maximum = 10);
69
70
80
81
87 const SpinButtonRenderer* getSharedRenderer() const;
88
95 const SpinButtonRenderer* getRenderer() const;
96
97
105 void setSize(const Layout2d& size) override;
106 using Widget::setSize;
107
108
118 void setMinimum(float minimum);
119
120
129 float getMinimum() const;
130
131
141 void setMaximum(float maximum);
142
143
152 float getMaximum() const;
153
154
164 void setValue(float value);
165
166
175 float getValue() const;
176
177
183 void setStep(float step);
184
185
191 float getStep() const;
192
193
200 void setVerticalScroll(bool vertical);
201
202
207 bool getVerticalScroll() const;
208
209
213 void leftMousePressed(Vector2f pos) override;
214
218 void leftMouseReleased(Vector2f pos) override;
219
223 void mouseMoved(Vector2f pos) override;
224
225
233 void draw(BackendRenderTargetBase& target, RenderStates states) const override;
234
235
237 protected:
238
248 Signal& getSignal(String signalName) override;
249
250
257 void rendererChanged(const String& property) override;
258
259
263 std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
264
265
269 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
270
271
273 // Returns the size of the arrows
275 Vector2f getArrowSize() const;
276
277
279 // Makes a copy of the widget
281 Widget::Ptr clone() const override
282 {
283 return std::make_shared<SpinButton>(*this);
284 }
285
286
288 private:
289
291 //
293 void callMousePressPeriodically(std::chrono::time_point<std::chrono::steady_clock> clicked);
294
295
297 public:
298
299 SignalFloat onValueChange = {"ValueChanged"};
300
301
303 protected:
304
305 // Is the spin button draw vertically (arrows on top of each other)?
306 bool m_verticalScroll = true;
307 std::chrono::time_point<std::chrono::steady_clock> m_PressedAt;
308
309 float m_minimum = 0;
310 float m_maximum = 10;
311 float m_value = 0;
312 float m_step = 1;
313
314 // On which arrow is the mouse?
315 bool m_mouseHoverOnTopArrow = false;
316 bool m_mouseDownOnTopArrow = false;
317
318 Sprite m_spriteArrowUp;
319 Sprite m_spriteArrowUpHover;
320 Sprite m_spriteArrowDown;
321 Sprite m_spriteArrowDownHover;
322
323 // Cached renderer properties
324 Borders m_bordersCached;
325 Color m_borderColorCached;
326 Color m_backgroundColorCached;
327 Color m_backgroundColorHoverCached;
328 Color m_arrowColorCached;
329 Color m_arrowColorHoverCached;
330 float m_borderBetweenArrowsCached = 0;
331 };
332
334}
335
337
338#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:262
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.
SpinButtonRenderer * getSharedRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
void draw(BackendRenderTargetBase &target, RenderStates states) const override
Draw the widget to a render target.
std::shared_ptr< const SpinButton > ConstPtr
Shared constant widget pointer.
Definition SpinButton.hpp:46
float getMaximum() const
Returns the maximum value.
std::shared_ptr< SpinButton > Ptr
Shared widget pointer.
Definition SpinButton.hpp:45
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.
void setSize(const Layout2d &size) override
Changes the size of the spin button.
static SpinButton::Ptr copy(SpinButton::ConstPtr spinButton)
Makes a copy of another spin button.
Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition SpinButton.hpp:281
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.
Definition Sprite.hpp:49
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