TGUI  0.7.8
SpinButton.hpp
1
2//
3// TGUI - Texus's Graphical User Interface
4// Copyright (C) 2012-2017 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/Widgets/ClickableWidget.hpp>
31
33
34namespace tgui
35{
36 class SpinButtonRenderer;
37
49 class TGUI_API SpinButton : public ClickableWidget
50 {
51 public:
52
53 typedef std::shared_ptr<SpinButton> Ptr;
54 typedef std::shared_ptr<const SpinButton> ConstPtr;
55
56
58 // Default constructor
60 SpinButton();
61
62
72 static SpinButton::Ptr create(int minimum = 0, int maximum = 10);
73
74
84
85
92 std::shared_ptr<SpinButtonRenderer> getRenderer() const
93 {
94 return std::static_pointer_cast<SpinButtonRenderer>(m_renderer);
95 }
96
97
110 virtual void setPosition(const Layout2d& position) override;
112
113
120 virtual void setSize(const Layout2d& size) override;
122
123
132 virtual sf::Vector2f getFullSize() const override;
133
134
144 void setMinimum(int minimum);
145
146
156 void setMaximum(int maximum);
157
158
168 void setValue(int value);
169
170
179 int getMinimum() const
180 {
181 return m_minimum;
182 }
183
184
193 int getMaximum() const
194 {
195 return m_maximum;
196 }
197
198
207 int getValue() const
208 {
209 return m_value;
210 }
211
212
219 void setVerticalScroll(bool verticalScroll);
220
221
228 bool getVerticalScroll() const
229 {
230 return m_verticalScroll;
231 }
232
233
240 virtual void setOpacity(float opacity) override;
241
242
251 virtual sf::Vector2f getWidgetOffset() const override;
252
253
257 virtual void leftMousePressed(float x, float y) override;
258
262 virtual void leftMouseReleased(float x, float y) override;
263
267 virtual void mouseMoved(float x, float y) override;
268
272 virtual void widgetFocused() override;
273
274
276 protected:
277
290 virtual void reload(const std::string& primary = "", const std::string& secondary = "", bool force = false) override;
291
292
294 // Makes a copy of the widget
296 virtual Widget::Ptr clone() const override
297 {
298 return std::make_shared<SpinButton>(*this);
299 }
300
301
303 // Draws the widget on the render target.
305 virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
306
307
309 protected:
310
311 // Is the spin button draw vertically (arrows on top of each other)?
312 bool m_verticalScroll = true;
313
314 int m_minimum = 0;
315 int m_maximum = 10;
316 int m_value = 0;
317
318 // On which arrow is the mouse?
319 bool m_mouseHoverOnTopArrow = false;
320 bool m_mouseDownOnTopArrow = false;
321
322 friend class SpinButtonRenderer;
323 };
324
325
327
328 class TGUI_API SpinButtonRenderer : public WidgetRenderer, public WidgetBorders
329 {
330 public:
331
338 SpinButtonRenderer(SpinButton* spinButton) : m_spinButton{spinButton} {}
339
340
350 virtual void setProperty(std::string property, const std::string& value) override;
351
352
363 virtual void setProperty(std::string property, ObjectConverter&& value) override;
364
365
375 virtual ObjectConverter getProperty(std::string property) const override;
376
377
384 virtual std::map<std::string, ObjectConverter> getPropertyValuePairs() const override;
385
386
400 void setBackgroundColor(const Color& color);
401
402
411 void setBackgroundColorNormal(const Color& color);
412
413
422 void setBackgroundColorHover(const Color& color);
423
424
438 void setArrowColor(const Color& color);
439
440
449 void setArrowColorNormal(const Color& color);
450
451
460 void setArrowColorHover(const Color& color);
461
462
469 void setBorderColor(const Color& color);
470
471
481 void setArrowUpTexture(const Texture& texture);
482
483
493 void setArrowDownTexture(const Texture& texture);
494
495
505 void setArrowUpHoverTexture(const Texture& texture);
506
507
517 void setArrowDownHoverTexture(const Texture& texture);
518
519
530 void setSpaceBetweenArrows(float space);
531
532
534 // Draws the widget on the render target.
536 void draw(sf::RenderTarget& target, sf::RenderStates states) const;
537
538
540 private:
541
543 // Makes a copy of the renderer
545 virtual std::shared_ptr<WidgetRenderer> clone(Widget* widget) override;
546
547
549 protected:
550
551 SpinButton* m_spinButton;
552
553 float m_spaceBetweenArrows = 2;
554
555 Texture m_textureArrowUpNormal;
556 Texture m_textureArrowUpHover;
557 Texture m_textureArrowDownNormal;
558 Texture m_textureArrowDownHover;
559
560 sf::Color m_backgroundColorNormal;
561 sf::Color m_backgroundColorHover;
562 sf::Color m_arrowColorNormal;
563 sf::Color m_arrowColorHover;
564
565 sf::Color m_borderColor;
566
567
568 friend class SpinButton;
569
571 };
572
574}
575
577
578#endif // TGUI_SPIN_BUTTON_HPP
Clickable widget.
Definition: ClickableWidget.hpp:56
Implicit converter for colors.
Definition: Color.hpp:40
Class to store the position or size of a widget.
Definition: Layout.hpp:255
Implicit converter for settable properties.
Definition: ObjectConverter.hpp:43
Definition: SpinButton.hpp:329
void setArrowUpTexture(const Texture &texture)
Change the image that is used as the up arrow.
void setArrowColorHover(const Color &color)
Changes the color of the arrows in the hover state (mouse standing on top of the spin button).
void setArrowColor(const Color &color)
Changes the color of the arrows.
virtual std::map< std::string, ObjectConverter > getPropertyValuePairs() const override
Get a map with all properties and their values.
void setArrowColorNormal(const Color &color)
Changes the color of the arrows in the normal state (mouse not on spin button).
void setBackgroundColorNormal(const Color &color)
Changes the background color of the arrows in the normal state (mouse not on spin button).
virtual void setProperty(std::string property, const std::string &value) override
Change a property of the renderer.
void setArrowDownTexture(const Texture &texture)
Change the image that is used as the down arrow.
virtual ObjectConverter getProperty(std::string property) const override
Retrieve the value of a certain property.
SpinButtonRenderer(SpinButton *spinButton)
Constructor.
Definition: SpinButton.hpp:338
void setBorderColor(const Color &color)
Changes the color of the borders that are optionally drawn around the arrows.
void setBackgroundColorHover(const Color &color)
Changes the background color of the arrows in the hover state (mouse standing on top of the spin butt...
void setArrowUpHoverTexture(const Texture &texture)
Change the image that is used as the up arrow when the mouse is on top of this arrow.
void setArrowDownHoverTexture(const Texture &texture)
Change the image that is used as the up arrow when the mouse is on top of this arrow.
void setSpaceBetweenArrows(float space)
Changes the space that is placed between the arrows.
void setBackgroundColor(const Color &color)
Changes the background color of the arrows.
virtual void setProperty(std::string property, ObjectConverter &&value) override
Change a property of the renderer.
Spin button widget.
Definition: SpinButton.hpp:50
virtual void reload(const std::string &primary="", const std::string &secondary="", bool force=false) override
Reload the widget.
std::shared_ptr< const SpinButton > ConstPtr
Shared constant widget pointer.
Definition: SpinButton.hpp:54
int getMinimum() const
Returns the minimum value.
Definition: SpinButton.hpp:179
virtual void setSize(const Layout2d &size) override
Changes the size of the spin button.
std::shared_ptr< SpinButton > Ptr
Shared widget pointer.
Definition: SpinButton.hpp:53
bool getVerticalScroll() const
Returns whether the spin button lies vertical or horizontal (arrows above or next to each other).
Definition: SpinButton.hpp:228
void setValue(int value)
Changes the current value.
virtual sf::Vector2f getWidgetOffset() const override
Returns the distance between the position where the widget is drawn and where the widget is placed.
static SpinButton::Ptr copy(SpinButton::ConstPtr spinButton)
Makes a copy of another spin button.
void setMaximum(int maximum)
Sets a maximum value.
virtual sf::Vector2f getFullSize() const override
Returns the full size of the spin button.
static SpinButton::Ptr create(int minimum=0, int maximum=10)
Creates a new spin button widget.
int getMaximum() const
Returns the maximum value.
Definition: SpinButton.hpp:193
virtual void setOpacity(float opacity) override
Changes the opacity of the widget.
std::shared_ptr< SpinButtonRenderer > getRenderer() const
Returns the renderer, which gives access to functions that determine how the widget is displayed.
Definition: SpinButton.hpp:92
virtual void setPosition(const Layout2d &position) override
Set the position of the widget.
void setVerticalScroll(bool verticalScroll)
Changes whether the spin button lies vertical or horizontal (arrows above or next to each other).
void setMinimum(int minimum)
Sets a minimum value.
int getValue() const
Returns the current value.
Definition: SpinButton.hpp:207
virtual Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition: SpinButton.hpp:296
Definition: Texture.hpp:45
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
virtual void setPosition(const Layout2d &position)
set the position of the widget
Parent class for every widget that has borders.
Definition: Borders.hpp:137
Base class for all renderer classes.
Definition: Widget.hpp:683
The parent class for every widget.
Definition: Widget.hpp:72
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:75
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:34