TGUI  0.7.8
ProgressBar.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_PROGRESS_BAR_HPP
27#define TGUI_PROGRESS_BAR_HPP
28
29
30#include <TGUI/Widgets/Label.hpp>
31
33
34namespace tgui
35{
36 class ProgressBarRenderer;
37
53 class TGUI_API ProgressBar : public ClickableWidget
54 {
55 public:
56
57 typedef std::shared_ptr<ProgressBar> Ptr;
58 typedef std::shared_ptr<const ProgressBar> ConstPtr;
59
60
67 enum class FillDirection
68 {
69 LeftToRight,
70 RightToLeft,
71 TopToBottom,
72 BottomToTop
73 };
74
75
80
81
89
90
100
101
108 std::shared_ptr<ProgressBarRenderer> getRenderer() const
109 {
110 return std::static_pointer_cast<ProgressBarRenderer>(m_renderer);
111 }
112
113
126 virtual void setPosition(const Layout2d& position) override;
128
129
136 void setSize(const Layout2d& size) override;
138
139
148 virtual sf::Vector2f getFullSize() const override;
149
150
159 virtual void setFont(const Font& font) override;
160
161
170 void setMinimum(unsigned int minimum);
171
172
181 void setMaximum(unsigned int maximum);
182
183
192 void setValue(unsigned int value);
193
194
201 unsigned int getMinimum() const
202 {
203 return m_minimum;
204 }
205
206
213 unsigned int getMaximum() const
214 {
215 return m_maximum;
216 }
217
218
225 unsigned int getValue() const
226 {
227 return m_value;
228 }
229
230
239 unsigned int incrementValue();
240
241
250 void setText(const sf::String& text);
251
252
259 sf::String getText() const
260 {
261 return m_textBack.getText();
262 }
263
264
272 void setTextSize(unsigned int size);
273
274
281 unsigned int getTextSize() const
282 {
283 return m_textBack.getTextSize();
284 }
285
286
296
297
307 {
308 return m_fillDirection;
309 }
310
311
318 virtual void setOpacity(float opacity) override;
319
320
329 virtual sf::Vector2f getWidgetOffset() const override;
330
331
333 protected:
334
347 virtual void reload(const std::string& primary = "", const std::string& secondary = "", bool force = false) override;
348
349
351 // Makes a copy of the widget
353 virtual Widget::Ptr clone() const override
354 {
355 return std::make_shared<ProgressBar>(*this);
356 }
357
358
360 // When the value changes, or when the minimum/maximum limits change then a smaller of bigger piece of the front image
361 // must be drawn. This function is called to calculate the size of the piece to draw.
363 void recalculateSize();
364
365
367 // Draws the widget on the render target.
369 virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
370
371
373 protected:
374
375 unsigned int m_minimum = 0;
376 unsigned int m_maximum = 100;
377 unsigned int m_value = 0;
378
379 Label m_textBack;
380 Label m_textFront;
381 unsigned int m_textSize = 0;
382
383 sf::FloatRect m_frontRect;
384
385 FillDirection m_fillDirection = FillDirection::LeftToRight;
386
387 friend class ProgressBarRenderer;
388 };
389
390
392
393 class TGUI_API ProgressBarRenderer : public WidgetRenderer, public WidgetBorders
394 {
395 public:
396
403 ProgressBarRenderer(ProgressBar* progressBar) : m_progressBar{progressBar} {}
404
405
415 virtual void setProperty(std::string property, const std::string& value) override;
416
417
428 virtual void setProperty(std::string property, ObjectConverter&& value) override;
429
430
440 virtual ObjectConverter getProperty(std::string property) const override;
441
442
449 virtual std::map<std::string, ObjectConverter> getPropertyValuePairs() const override;
450
451
463 void setTextColor(const Color& color);
464
465
474 void setTextColorBack(const Color& color);
475
476
485 void setTextColorFront(const Color& color);
486
487
498 void setBackgroundColor(const Color& color);
499
500
511 void setForegroundColor(const Color& color);
512
513
520 void setBorderColor(const Color& color);
521
522
532 void setBackTexture(const Texture& texture);
533
534
544 void setFrontTexture(const Texture& texture);
545
546
548 // Draws the widget on the render target.
550 void draw(sf::RenderTarget& target, sf::RenderStates states) const;
551
552
554 private:
555
557 // Makes a copy of the renderer
559 virtual std::shared_ptr<WidgetRenderer> clone(Widget* widget) override;
560
561
563 protected:
564
565 ProgressBar* m_progressBar;
566
567 Texture m_textureBack;
568 Texture m_textureFront;
569
570 sf::Color m_textColorFront;
571 sf::Color m_textColorBack;
572
573 sf::Color m_backgroundColor;
574 sf::Color m_foregroundColor;
575
576 sf::Color m_borderColor;
577
578 friend class ProgressBar;
579
581 };
582
584}
585
587
588#endif // TGUI_PROGRESS_BAR_HPP
Clickable widget.
Definition: ClickableWidget.hpp:56
Implicit converter for colors.
Definition: Color.hpp:40
Definition: Font.hpp:38
Label widget.
Definition: Label.hpp:50
Class to store the position or size of a widget.
Definition: Layout.hpp:255
Implicit converter for settable properties.
Definition: ObjectConverter.hpp:43
Definition: ProgressBar.hpp:394
void setBorderColor(const Color &color)
Changes the border color.
void setTextColor(const Color &color)
Changes the color of the text that is optionally displayed on top of the progress bar.
void setForegroundColor(const Color &color)
Changes the foreground color of the progress bar.
void setTextColorFront(const Color &color)
Changes the color of the text that is optionally displayed on top of the progress bar.
void setFrontTexture(const Texture &texture)
Change the foreground image of the progress bar.
ProgressBarRenderer(ProgressBar *progressBar)
Constructor.
Definition: ProgressBar.hpp:403
virtual std::map< std::string, ObjectConverter > getPropertyValuePairs() const override
Get a map with all properties and their values.
virtual void setProperty(std::string property, ObjectConverter &&value) override
Change a property of the renderer.
void setBackTexture(const Texture &texture)
Change the background image of the progress bar.
void setTextColorBack(const Color &color)
Changes the color of the text that is optionally displayed on top of the progress bar.
void setBackgroundColor(const Color &color)
Changes the background color of the progress bar.
virtual ObjectConverter getProperty(std::string property) const override
Retrieve the value of a certain property.
virtual void setProperty(std::string property, const std::string &value) override
Change a property of the renderer.
Progress bar widget.
Definition: ProgressBar.hpp:54
virtual sf::Vector2f getWidgetOffset() const override
Returns the distance between the position where the widget is drawn and where the widget is placed.
std::shared_ptr< ProgressBarRenderer > getRenderer() const
Returns the renderer, which gives access to functions that determine how the widget is displayed.
Definition: ProgressBar.hpp:108
virtual void setPosition(const Layout2d &position) override
Set the position of the widget.
unsigned int getValue() const
Returns the current value.
Definition: ProgressBar.hpp:225
void setFillDirection(FillDirection direction)
Changes the fill direction of the progress bar.
virtual void setFont(const Font &font) override
Changes the font of the text in the widget.
void setMaximum(unsigned int maximum)
Sets a maximum value.
static ProgressBar::Ptr copy(ProgressBar::ConstPtr progressBar)
Makes a copy of another progress bar.
sf::String getText() const
Returns the caption of the progress bar.
Definition: ProgressBar.hpp:259
std::shared_ptr< const ProgressBar > ConstPtr
Shared constant widget pointer.
Definition: ProgressBar.hpp:58
virtual void setOpacity(float opacity) override
Changes the opacity of the widget.
virtual void reload(const std::string &primary="", const std::string &secondary="", bool force=false) override
Reload the widget.
std::shared_ptr< ProgressBar > Ptr
Shared widget pointer.
Definition: ProgressBar.hpp:57
ProgressBar()
Default constructor.
virtual Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition: ProgressBar.hpp:353
void setValue(unsigned int value)
Changes the current value.
unsigned int incrementValue()
Increment the value.
void setMinimum(unsigned int minimum)
Sets a minimum value.
void setSize(const Layout2d &size) override
Changes the size of the progress bar.
static ProgressBar::Ptr create()
Creates a new progress bar widget.
FillDirection
The fill direction of the progress bar.
Definition: ProgressBar.hpp:68
void setText(const sf::String &text)
Changes the caption of the progress bar.
unsigned int getMinimum() const
Returns the minimum value.
Definition: ProgressBar.hpp:201
void setTextSize(unsigned int size)
Changes the character size of the text.
unsigned int getMaximum() const
Returns the maximum value.
Definition: ProgressBar.hpp:213
FillDirection getFillDirection()
Returns the fill direction of the progress bar.
Definition: ProgressBar.hpp:306
virtual sf::Vector2f getFullSize() const override
Returns the full size of the progress bar.
unsigned int getTextSize() const
Returns the character size of the text.
Definition: ProgressBar.hpp:281
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