TGUI  0.7.8
Scrollbar.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_SCROLLBAR_HPP
27#define TGUI_SCROLLBAR_HPP
28
29
30#include <TGUI/Widget.hpp>
31
33
34namespace tgui
35{
36 class ScrollbarRenderer;
37
49 class TGUI_API Scrollbar : public Widget
50 {
51 public:
52
53 typedef std::shared_ptr<Scrollbar> Ptr;
54 typedef std::shared_ptr<const Scrollbar> ConstPtr;
55
56
58 // Default constructor
60 Scrollbar();
61
62
70
71
81
82
89 std::shared_ptr<ScrollbarRenderer> getRenderer() const
90 {
91 return std::static_pointer_cast<ScrollbarRenderer>(m_renderer);
92 }
93
94
107 virtual void setPosition(const Layout2d& position) override;
109
110
117 void setSize(const Layout2d& size) override;
119
120
130 void setMaximum(unsigned int maximum);
131
132
141 void setValue(unsigned int value);
142
143
155 void setLowValue(unsigned int lowValue);
156
157
166 unsigned int getMaximum() const
167 {
168 return m_maximum;
169 }
170
171
180 unsigned int getValue() const
181 {
182 return m_value;
183 }
184
185
192 unsigned int getLowValue() const
193 {
194 return m_lowValue;
195 }
196
197
204 void setArrowScrollAmount(unsigned int scrollAmount)
205 {
206 m_scrollAmount = scrollAmount;
207 }
208
209
216 unsigned int getArrowScrollAmount()
217 {
218 return m_scrollAmount;
219 }
220
221
230 void setAutoHide(bool autoHide)
231 {
232 m_autoHide = autoHide;
233 }
234
235
243 bool getAutoHide() const
244 {
245 return m_autoHide;
246 }
247
248
255 virtual void setOpacity(float opacity) override;
256
257
261 virtual bool mouseOnWidget(float x, float y) const override;
262
266 virtual void leftMousePressed(float x, float y) override;
267
271 virtual void leftMouseReleased(float x, float y) override;
272
276 virtual void mouseMoved(float x, float y) override;
277
281 virtual void mouseWheelMoved(int delta, int x, int y) override;
282
286 virtual void widgetFocused() override;
287
291 virtual void mouseNoLongerDown() override;
292
293
295 protected:
296
309 virtual void reload(const std::string& primary = "", const std::string& secondary = "", bool force = false) override;
310
311
313 // Makes a copy of the widget
315 virtual Widget::Ptr clone() const override
316 {
317 return std::make_shared<Scrollbar>(*this);
318 }
319
320
322 // Draws the widget on the render target.
324 virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
325
326
328 protected:
329
330 enum class Part
331 {
332 Track,
333 Thumb,
334 ArrowUp,
335 ArrowDown
336 };
337
338 // Keep track on which part of the scrollbar the mouse is standing
339 Part m_mouseHoverOverPart = Part::Thumb;
340
341 // When the mouse went down, did it go down on top of the thumb? If so, where?
342 bool m_mouseDownOnThumb = false;
343 sf::Vector2f m_mouseDownOnThumbPos;
344
345 unsigned int m_maximum = 10;
346 unsigned int m_value = 0;
347
348 // Maximum should be above this value before the scrollbar is needed
349 unsigned int m_lowValue = 6;
350
351 // Is the scrollbar draw vertically?
352 bool m_verticalScroll = true;
353
354 // Does the image lie vertically?
355 bool m_verticalImage = true;
356
357 // How far should the value change when pressing one of the arrows?
358 unsigned int m_scrollAmount = 1;
359
360 // When no scrollbar is needed, should the scrollbar be drawn or stay hidden?
361 bool m_autoHide = true;
362
363 // Did the mouse went down on one of the arrows?
364 bool m_mouseDownOnArrow = false;
365
366 sf::FloatRect m_track;
367 sf::FloatRect m_thumb;
368 sf::FloatRect m_arrowUp;
369 sf::FloatRect m_arrowDown;
370
371 // ListBox, ComboBox and TextBox can access the scrollbar directly
372 friend class ListBox;
373 friend class ComboBox;
374 friend class TextBox;
375 friend class ChatBox;
376
377 friend class ScrollbarRenderer;
378
380
381 };
382
383
385
386 class TGUI_API ScrollbarRenderer : public WidgetRenderer
387 {
388 public:
389
396 ScrollbarRenderer(Scrollbar* scrollbar) : m_scrollbar{scrollbar} {}
397
398
408 virtual void setProperty(std::string property, const std::string& value) override;
409
410
421 virtual void setProperty(std::string property, ObjectConverter&& value) override;
422
423
433 virtual ObjectConverter getProperty(std::string property) const override;
434
435
442 virtual std::map<std::string, ObjectConverter> getPropertyValuePairs() const override;
443
444
458 void setTrackColor(const Color& color);
459
460
469 void setTrackColorNormal(const Color& color);
470
471
480 void setTrackColorHover(const Color& color);
481
482
496 void setThumbColor(const Color& color);
497
498
507 void setThumbColorNormal(const Color& color);
508
509
518 void setThumbColorHover(const Color& color);
519
520
534 void setArrowBackgroundColor(const Color& color);
535
536
546
547
557
558
572 void setArrowColor(const Color& color);
573
574
583 void setArrowColorNormal(const Color& color);
584
585
594 void setArrowColorHover(const Color& color);
595
596
606 void setTrackTexture(const Texture& texture);
607
608
618 void setTrackHoverTexture(const Texture& texture);
619
620
630 void setThumbTexture(const Texture& texture);
631
632
642 void setThumbHoverTexture(const Texture& texture);
643
644
654 void setArrowUpTexture(const Texture& texture);
655
656
666 void setArrowDownTexture(const Texture& texture);
667
668
678 void setArrowUpHoverTexture(const Texture& texture);
679
680
690 void setArrowDownHoverTexture(const Texture& texture);
691
692
694 // Draws the widget on the render target.
696 void draw(sf::RenderTarget& target, sf::RenderStates states) const;
697
698
700 private:
701
703 // Makes a copy of the renderer
705 virtual std::shared_ptr<WidgetRenderer> clone(Widget* widget) override;
706
707
709 protected:
710
711 Scrollbar* m_scrollbar;
712
713 Texture m_textureTrackNormal;
714 Texture m_textureTrackHover;
715 Texture m_textureThumbNormal;
716 Texture m_textureThumbHover;
717 Texture m_textureArrowUpNormal;
718 Texture m_textureArrowUpHover;
719 Texture m_textureArrowDownNormal;
720 Texture m_textureArrowDownHover;
721
722 sf::Color m_trackColorNormal = {255, 255, 255};
723 sf::Color m_trackColorHover = {255, 255, 255};
724 sf::Color m_thumbColorNormal = {220, 220, 220};
725 sf::Color m_thumbColorHover = {210, 210, 210};
726 sf::Color m_arrowBackgroundColorNormal = {245, 245, 245};
727 sf::Color m_arrowBackgroundColorHover = {255, 255, 255};
728 sf::Color m_arrowColorNormal = { 60, 60, 60};
729 sf::Color m_arrowColorHover = { 0, 0, 0};
730
731 friend class Scrollbar;
732
734 };
735
737}
738
740
741#endif // TGUI_SCROLLBAR_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: Scrollbar.hpp:387
void setTrackColorHover(const Color &color)
Changes the color of the track in hover state (mouse on top of the track).
void setArrowUpTexture(const Texture &texture)
Change the image that is used as the up arrow.
virtual void setProperty(std::string property, const std::string &value) override
Change a property of the renderer.
void setArrowColorHover(const Color &color)
Changes the color of the arrows in the hover state (mouse standing on top of the 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 setTrackColor(const Color &color)
Changes the color of the track.
void setTrackTexture(const Texture &texture)
Change the image of the track that is displayed when the mouse is not on top of the scrollbar.
void setThumbColorNormal(const Color &color)
Changes the color of the thumb in the normal state (mouse not on the thumb).
void setThumbColorHover(const Color &color)
Changes the color of the thumb in hover state (mouse on top of the thumb).
void setTrackColorNormal(const Color &color)
Changes the color of the track in the normal state (mouse not on the track).
ScrollbarRenderer(Scrollbar *scrollbar)
Constructor.
Definition: Scrollbar.hpp:396
void setThumbTexture(const Texture &texture)
Change the image of the thumb that is displayed when the mouse is not on top of the slider.
virtual std::map< std::string, ObjectConverter > getPropertyValuePairs() const override
Get a map with all properties and their values.
void setArrowColor(const Color &color)
Changes the color of the arrows.
void setArrowBackgroundColorHover(const Color &color)
Changes the background color of the arrows in the hover state (mouse standing on top of the arrow).
void setThumbColor(const Color &color)
Changes the color of the thumb.
virtual void setProperty(std::string property, ObjectConverter &&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.
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 setTrackHoverTexture(const Texture &texture)
Change the image of the track that is displayed when the mouse is on top of the slider.
void setThumbHoverTexture(const Texture &texture)
Change the image of the thumb that is displayed when the mouse is on top of the slider.
void setArrowColorNormal(const Color &color)
Changes the color of the arrows in the normal state (mouse not on arrow).
void setArrowBackgroundColor(const Color &color)
Changes the background color of the arrows.
void setArrowBackgroundColorNormal(const Color &color)
Changes the background color of the arrows in the normal state (mouse not on arrow).
Scrollbar widget.
Definition: Scrollbar.hpp:50
unsigned int getMaximum() const
Returns the maximum value.
Definition: Scrollbar.hpp:166
void setValue(unsigned int value)
Changes the current value.
static Scrollbar::Ptr create()
Creates a new scrollbar widget.
void setMaximum(unsigned int maximum)
Sets a maximum value.
void setSize(const Layout2d &size) override
Changes the size of the scrollbar.
unsigned int getLowValue() const
Returns the low value.
Definition: Scrollbar.hpp:192
virtual Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition: Scrollbar.hpp:315
virtual void setOpacity(float opacity) override
Changes the opacity of the widget.
void setArrowScrollAmount(unsigned int scrollAmount)
Changes how much the value changes when pressing one of the arrows of the scrollbar.
Definition: Scrollbar.hpp:204
std::shared_ptr< ScrollbarRenderer > getRenderer() const
Returns the renderer, which gives access to functions that determine how the widget is displayed.
Definition: Scrollbar.hpp:89
unsigned int getValue() const
Returns the current value.
Definition: Scrollbar.hpp:180
std::shared_ptr< Scrollbar > Ptr
Shared widget pointer.
Definition: Scrollbar.hpp:53
unsigned int getArrowScrollAmount()
Returns how much the value changes when pressing one of the arrows of the scrollbar.
Definition: Scrollbar.hpp:216
std::shared_ptr< const Scrollbar > ConstPtr
Shared constant widget pointer.
Definition: Scrollbar.hpp:54
void setAutoHide(bool autoHide)
Changes whether the scrollbar should hide automatically or not.
Definition: Scrollbar.hpp:230
static Scrollbar::Ptr copy(Scrollbar::ConstPtr scrollbar)
Makes a copy of another scrollbar.
virtual void reload(const std::string &primary="", const std::string &secondary="", bool force=false) override
Reload the widget.
void setLowValue(unsigned int lowValue)
Changes the 'low value'.
bool getAutoHide() const
Returns whether the scrollbar is hiding automatically or not.
Definition: Scrollbar.hpp:243
virtual void setPosition(const Layout2d &position) override
Set the position of the widget.
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
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