TGUI  1.3-dev
Loading...
Searching...
No Matches
ProgressBar.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2024 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
36TGUI_MODULE_EXPORT namespace tgui
37{
41 class TGUI_API ProgressBar : public ClickableWidget
42 {
43 public:
44
45 using Ptr = std::shared_ptr<ProgressBar>;
46 using ConstPtr = std::shared_ptr<const ProgressBar>;
47
48 static constexpr const char StaticWidgetType[] = "ProgressBar";
49
50
57 enum class FillDirection
58 {
59 LeftToRight,
60 RightToLeft,
61 TopToBottom,
62 BottomToTop
63 };
64
65
73 ProgressBar(const char* typeName = StaticWidgetType, bool initRenderer = true);
74
75
82 TGUI_NODISCARD static ProgressBar::Ptr create();
83
84
93 TGUI_NODISCARD static ProgressBar::Ptr copy(const ProgressBar::ConstPtr& progressBar);
94
95
100 TGUI_NODISCARD ProgressBarRenderer* getSharedRenderer() override;
101 TGUI_NODISCARD const ProgressBarRenderer* getSharedRenderer() const override;
102
108 TGUI_NODISCARD ProgressBarRenderer* getRenderer() override;
109
110
117 void setSize(const Layout2d& size) override;
118 using Widget::setSize;
119
120
129 void setMinimum(unsigned int minimum);
130
131
138 TGUI_NODISCARD unsigned int getMinimum() const;
139
140
149 void setMaximum(unsigned int maximum);
150
151
158 TGUI_NODISCARD unsigned int getMaximum() const;
159
160
169 void setValue(unsigned int value);
170
171
178 TGUI_NODISCARD unsigned int getValue() const;
179
180
189 unsigned int incrementValue();
190
191
200 void setText(const String& text);
201
202
209 TGUI_NODISCARD const String& getText() const;
210
211
221
222
231 TGUI_NODISCARD FillDirection getFillDirection() const;
232
233
238 TGUI_NODISCARD bool isMouseOnWidget(Vector2f pos) const override;
239
240
248 void draw(BackendRenderTarget& target, RenderStates states) const override;
249
250
252 protected:
253
263 TGUI_NODISCARD Signal& getSignal(String signalName) override;
264
265
272 void rendererChanged(const String& property) override;
273
274
278 TGUI_NODISCARD std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
279
280
284 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
285
286
290 void updateTextSize() override;
291
292
294 // Returns the size without the borders
296 TGUI_NODISCARD Vector2f getInnerSize() const;
297
298
300 // When the value changes, or when the minimum/maximum limits change then a smaller of bigger piece of the front image
301 // must be drawn. This function is called to calculate the size of the piece to draw.
303 void recalculateFillSize();
304
305
307 // Returns the size of the front image.
309 TGUI_NODISCARD Vector2f getFrontImageSize() const;
310
311
313 // Makes a copy of the widget
315 TGUI_NODISCARD Widget::Ptr clone() const override;
316
317
319 public:
320
321 SignalUInt onValueChange = {"ValueChanged"};
322 Signal onFull = {"Full"};
323
324
326 protected:
327
328 unsigned int m_minimum = 0;
329 unsigned int m_maximum = 100;
330 unsigned int m_value = 0;
331
332 Text m_textBack;
333 Text m_textFront;
334
335 FloatRect m_backRect;
336 FloatRect m_frontRect;
337
338 FillDirection m_fillDirection = FillDirection::LeftToRight;
339
340 Sprite m_spriteBackground;
341 Sprite m_spriteFill;
342
343 // Cached renderer properties
344 Borders m_bordersCached;
345 Color m_borderColorCached;
346 Color m_backgroundColorCached;
347 Color m_fillColorCached;
348 };
349
350
352}
353
355
356#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:72
Class to store the position or size of a widget.
Definition Layout.hpp:305
Definition Outline.hpp:39
Definition ProgressBarRenderer.hpp:37
Progress bar widget.
Definition ProgressBar.hpp:42
TGUI_NODISCARD ProgressBarRenderer * getSharedRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
void setFillDirection(FillDirection direction)
Changes the fill direction of the progress bar.
TGUI_NODISCARD Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
void setMaximum(unsigned int maximum)
Sets a maximum value.
TGUI_NODISCARD unsigned int getValue() const
Returns the current value.
void updateTextSize() override
Called when the text size is changed (either by setTextSize or via the renderer)
std::shared_ptr< ProgressBar > Ptr
Shared widget pointer.
Definition ProgressBar.hpp:45
TGUI_NODISCARD Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
static TGUI_NODISCARD ProgressBar::Ptr copy(const ProgressBar::ConstPtr &progressBar)
Makes a copy of another progress bar.
TGUI_NODISCARD 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.
TGUI_NODISCARD ProgressBarRenderer * getRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
TGUI_NODISCARD unsigned int getMinimum() const
Returns the minimum value.
std::shared_ptr< const ProgressBar > ConstPtr
Shared constant widget pointer.
Definition ProgressBar.hpp:46
void setValue(unsigned int value)
Changes the current value.
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.
FillDirection
The fill direction of the progress bar.
Definition ProgressBar.hpp:58
TGUI_NODISCARD FillDirection getFillDirection() const
Returns the fill direction of the progress bar.
TGUI_NODISCARD bool isMouseOnWidget(Vector2f pos) const override
Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget...
void draw(BackendRenderTarget &target, RenderStates states) const override
Draw the widget to a render target.
static TGUI_NODISCARD ProgressBar::Ptr create()
Creates a new progress bar widget.
void rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
TGUI_NODISCARD 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.
TGUI_NODISCARD unsigned int getMaximum() const
Returns the maximum value.
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:62
Definition Sprite.hpp:48
Wrapper class to store strings.
Definition String.hpp:101
Backend-independent wrapper around the backend-specific text class.
Definition Text.hpp:50
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition Widget.hpp:87
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:39
States used for drawing.
Definition RenderStates.hpp:39