TGUI  0.9-dev
ProgressBar.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2021 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/Renderers/ProgressBarRenderer.hpp>
31#include <TGUI/Widgets/ClickableWidget.hpp>
32#include <TGUI/Text.hpp>
33
35
36namespace tgui
37{
41 class TGUI_API ProgressBar : public ClickableWidget
42 {
43 public:
44
45 typedef std::shared_ptr<ProgressBar> Ptr;
46 typedef std::shared_ptr<const ProgressBar> ConstPtr;
47
48
55 enum class FillDirection
56 {
57 LeftToRight,
58 RightToLeft,
59 TopToBottom,
60 BottomToTop
61 };
62
63
71 ProgressBar(const char* typeName = "ProgressBar", bool initRenderer = true);
72
73
81
82
92
93
99 const ProgressBarRenderer* getSharedRenderer() const;
100
107 const ProgressBarRenderer* getRenderer() const;
108
109
116 void setSize(const Layout2d& size) override;
117 using Widget::setSize;
118
119
128 void setMinimum(unsigned int minimum);
129
130
137 unsigned int getMinimum() const;
138
139
148 void setMaximum(unsigned int maximum);
149
150
157 unsigned int getMaximum() const;
158
159
168 void setValue(unsigned int value);
169
170
177 unsigned int getValue() const;
178
179
188 unsigned int incrementValue();
189
190
199 void setText(const String& text);
200
201
208 const String& getText() const;
209
210
218 void setTextSize(unsigned int size) override;
219
220
227 unsigned int getTextSize() const override;
228
229
239
240
250
251
256 bool isMouseOnWidget(Vector2f pos) const override;
257
258
266 void draw(BackendRenderTarget& target, RenderStates states) const override;
267
268
270 protected:
271
281 Signal& getSignal(String signalName) override;
282
283
290 void rendererChanged(const String& property) override;
291
292
296 std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
297
298
302 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
303
304
306 // Returns the size without the borders
308 Vector2f getInnerSize() const;
309
310
312 // When the value changes, or when the minimum/maximum limits change then a smaller of bigger piece of the front image
313 // must be drawn. This function is called to calculate the size of the piece to draw.
315 void recalculateFillSize();
316
317
319 // Returns the size of the front image.
321 Vector2f getFrontImageSize() const;
322
323
325 // Makes a copy of the widget
327 Widget::Ptr clone() const override
328 {
329 return std::make_shared<ProgressBar>(*this);
330 }
331
332
334 public:
335
336 SignalUInt onValueChange = {"ValueChanged"};
337 Signal onFull = {"Full"};
338
339
341 protected:
342
343 unsigned int m_minimum = 0;
344 unsigned int m_maximum = 100;
345 unsigned int m_value = 0;
346
347 Text m_textBack;
348 Text m_textFront;
349
350 FloatRect m_backRect;
351 FloatRect m_frontRect;
352
353 FillDirection m_fillDirection = FillDirection::LeftToRight;
354
355 Sprite m_spriteBackground;
356 Sprite m_spriteFill;
357
358 // Cached renderer properties
359 Borders m_bordersCached;
360 Color m_borderColorCached;
361 Color m_backgroundColorCached;
362 Color m_fillColorCached;
363 };
364
365
367}
368
370
371#endif // TGUI_PROGRESS_BAR_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
Definition: ProgressBarRenderer.hpp:37
Progress bar widget.
Definition: ProgressBar.hpp:42
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition: ProgressBar.hpp:327
FillDirection getFillDirection() const
Returns the fill direction of the progress bar.
unsigned int getValue() const
Returns the current value.
void setFillDirection(FillDirection direction)
Changes the fill direction of the progress bar.
void setMaximum(unsigned int maximum)
Sets a maximum value.
bool isMouseOnWidget(Vector2f pos) const override
Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget...
static ProgressBar::Ptr copy(ProgressBar::ConstPtr progressBar)
Makes a copy of another progress bar.
std::shared_ptr< const ProgressBar > ConstPtr
Shared constant widget pointer.
Definition: ProgressBar.hpp:46
ProgressBarRenderer * getRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
std::shared_ptr< ProgressBar > Ptr
Shared widget pointer.
Definition: ProgressBar.hpp:45
void setValue(unsigned int value)
Changes the current value.
Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
unsigned int incrementValue()
Increments the value.
void setMinimum(unsigned int minimum)
Sets a minimum value.
void setText(const String &text)
Changes the caption of the progress bar.
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:56
void draw(BackendRenderTarget &target, RenderStates states) const override
Draw the widget to a render target.
unsigned int getMinimum() const
Returns the minimum value.
unsigned int getMaximum() const
Returns the maximum value.
unsigned int getTextSize() const override
Returns the character size of the text.
void rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
ProgressBarRenderer * getSharedRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
const String & getText() const
Returns the caption of the progress bar.
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
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 setTextSize(unsigned int size) override
Changes the character size of the text.
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:58
Definition: Sprite.hpp:45
Wrapper class to store strings.
Definition: String.hpp:79
Definition: Text.hpp:44
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:73
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
States used for drawing.
Definition: RenderStates.hpp:39