TGUI  0.7.8
Slider.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_SLIDER_HPP
27#define TGUI_SLIDER_HPP
28
29
30#include <TGUI/Widget.hpp>
31
33
34namespace tgui
35{
36 class SliderRenderer;
37
49 class TGUI_API Slider : public Widget
50 {
51 public:
52
53 typedef std::shared_ptr<Slider> Ptr;
54 typedef std::shared_ptr<const Slider> ConstPtr;
55
56
58 // Default constructor
60 Slider();
61
62
72 static Slider::Ptr create(int minimum = 0, int maximum = 10);
73
74
84
85
92 std::shared_ptr<SliderRenderer> getRenderer() const
93 {
94 return std::static_pointer_cast<SliderRenderer>(m_renderer);
95 }
96
97
110 virtual void setPosition(const Layout2d& position) override;
112
113
120 void setSize(const Layout2d& size) override;
122
123
132 virtual sf::Vector2f getFullSize() const override;
133
134
145 virtual void setMinimum(int minimum);
146
147
158 virtual void setMaximum(int maximum);
159
160
170 virtual void setValue(int value);
171
172
181 int getMinimum() const
182 {
183 return m_minimum;
184 }
185
186
195 int getMaximum() const
196 {
197 return m_maximum;
198 }
199
200
209 int getValue() const
210 {
211 return m_value;
212 }
213
214
221 virtual void setOpacity(float opacity) override;
222
223
232 virtual sf::Vector2f getWidgetOffset() const override;
233
234
238 virtual bool mouseOnWidget(float x, float y) const override;
239
243 virtual void leftMousePressed(float x, float y) override;
244
248 virtual void leftMouseReleased(float x, float y) override;
249
253 virtual void mouseMoved(float x, float y) override;
254
258 virtual void mouseWheelMoved(int delta, int x, int y) override;
259
263 virtual void widgetFocused() override;
264
268 virtual void mouseNoLongerDown() override;
269
270
272 protected:
273
286 virtual void reload(const std::string& primary = "", const std::string& secondary = "", bool force = false) override;
287
288
290 // Makes a copy of the widget
292 virtual Widget::Ptr clone() const override
293 {
294 return std::make_shared<Slider>(*this);
295 }
296
297
299 // Draws the widget on the render target.
301 virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
302
303
305 protected:
306
307 sf::FloatRect m_thumb;
308
309 // When the mouse went down, did it go down on top of the thumb? If so, where?
310 bool m_mouseDownOnThumb = false;
311 sf::Vector2f m_mouseDownOnThumbPos;
312
313 int m_minimum = 0;
314 int m_maximum = 10;
315 int m_value = 0;
316
317 // Is the slider drawn vertically?
318 bool m_verticalScroll = false;
319
320 // Does the image lie vertically?
321 bool m_verticalImage = false;
322
323
324 friend class SliderRenderer;
325 };
326
327
329
330 class TGUI_API SliderRenderer : public WidgetRenderer, public WidgetBorders
331 {
332 public:
333
340 SliderRenderer(Slider* slider) : m_slider{slider} {}
341
342
352 virtual void setProperty(std::string property, const std::string& value) override;
353
354
365 virtual void setProperty(std::string property, ObjectConverter&& value) override;
366
367
377 virtual ObjectConverter getProperty(std::string property) const override;
378
379
386 virtual std::map<std::string, ObjectConverter> getPropertyValuePairs() const override;
387
388
402 void setTrackColor(const Color& color);
403
404
413 void setTrackColorNormal(const Color& color);
414
415
424 void setTrackColorHover(const Color& color);
425
426
440 void setThumbColor(const Color& color);
441
442
451 void setThumbColorNormal(const Color& color);
452
453
462 void setThumbColorHover(const Color& color);
463
464
471 void setBorderColor(const Color& color);
472
473
483 void setTrackTexture(const Texture& texture);
484
485
495 void setTrackHoverTexture(const Texture& texture);
496
497
507 void setThumbTexture(const Texture& texture);
508
509
519 void setThumbHoverTexture(const Texture& texture);
520
521
523 // Draws the widget on the render target.
525 void draw(sf::RenderTarget& target, sf::RenderStates states) const;
526
527
529 private:
530
532 // Makes a copy of the renderer
534 virtual std::shared_ptr<WidgetRenderer> clone(Widget* widget) override;
535
536
538 protected:
539
540 Slider* m_slider;
541
542 Texture m_textureTrackNormal;
543 Texture m_textureTrackHover;
544 Texture m_textureThumbNormal;
545 Texture m_textureThumbHover;
546
547 sf::Color m_trackColorNormal;
548 sf::Color m_trackColorHover;
549
550 sf::Color m_thumbColorNormal;
551 sf::Color m_thumbColorHover;
552
553 sf::Color m_borderColor;
554
555 friend class Slider;
556
558 };
559
561}
562
564
565#endif // TGUI_SLIDER_HPP
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: Slider.hpp:331
void setBorderColor(const Color &color)
Changes the color of the borders.
void setThumbHoverTexture(const Texture &texture)
Change the image of the thumb that is displayed when the mouse is on top of the slider.
virtual std::map< std::string, ObjectConverter > getPropertyValuePairs() const override
Get a map with all properties and their values.
void setTrackTexture(const Texture &texture)
Change the image of the track that is displayed when the mouse is not on top of the slider.
void setThumbColorHover(const Color &color)
Changes the color of the thumb in hover state (mouse on slider).
void setTrackColor(const Color &color)
Changes the color of the track.
virtual void setProperty(std::string property, ObjectConverter &&value) override
Change a property of the renderer.
SliderRenderer(Slider *slider)
Constructor.
Definition: Slider.hpp:340
virtual ObjectConverter getProperty(std::string property) const override
Retrieve the value of a certain property.
void setThumbColor(const Color &color)
Changes the color of the thumb.
void setTrackColorNormal(const Color &color)
Changes the color of the track in the normal state (mouse not on slider).
void setTrackColorHover(const Color &color)
Changes the color of the track in hover state (mouse on slider).
void setTrackHoverTexture(const Texture &texture)
Change the image of the track that is displayed when the mouse is on top of the slider.
virtual void setProperty(std::string property, const std::string &value) override
Change a property of the renderer.
void setThumbTexture(const Texture &texture)
Change the image of the thumb that is displayed when the mouse is not on top of the slider.
void setThumbColorNormal(const Color &color)
Changes the color of the thumb in the normal state (mouse not on slider).
Slider widget.
Definition: Slider.hpp:50
std::shared_ptr< Slider > Ptr
Shared widget pointer.
Definition: Slider.hpp:53
int getMinimum() const
Returns the minimum value.
Definition: Slider.hpp:181
virtual void setOpacity(float opacity) override
Changes the opacity of the widget.
virtual void setPosition(const Layout2d &position) override
Set the position of the widget.
int getValue() const
Returns the current value.
Definition: Slider.hpp:209
virtual void setValue(int value)
Changes the current value.
virtual void setMaximum(int maximum)
Sets a maximum value.
virtual sf::Vector2f getWidgetOffset() const override
Returns the distance between the position where the widget is drawn and where the widget is placed.
virtual sf::Vector2f getFullSize() const override
Returns the full size of the slider.
std::shared_ptr< SliderRenderer > getRenderer() const
Returns the renderer, which gives access to functions that determine how the widget is displayed.
Definition: Slider.hpp:92
std::shared_ptr< const Slider > ConstPtr
Shared constant widget pointer.
Definition: Slider.hpp:54
int getMaximum() const
Returns the maximum value.
Definition: Slider.hpp:195
virtual void setMinimum(int minimum)
Sets a minimum value.
void setSize(const Layout2d &size) override
Changes the size of the slider.
virtual Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition: Slider.hpp:292
static Slider::Ptr create(int minimum=0, int maximum=10)
Creates a new slider widget.
virtual void reload(const std::string &primary="", const std::string &secondary="", bool force=false) override
Reload the widget.
static Slider::Ptr copy(Slider::ConstPtr slider)
Makes a copy of another slider.
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