TGUI  0.8-dev
ProgressBar.hpp
1 //
3 // TGUI - Texus' 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/Renderers/ProgressBarRenderer.hpp>
31 #include <TGUI/Widgets/ClickableWidget.hpp>
32 #include <TGUI/Text.hpp>
33 
35 
36 namespace 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 
65  // Default constructor
67  ProgressBar();
68 
69 
76  static ProgressBar::Ptr create();
77 
78 
87  static ProgressBar::Ptr copy(ProgressBar::ConstPtr progressBar);
88 
89 
94  ProgressBarRenderer* getSharedRenderer();
95  const ProgressBarRenderer* getSharedRenderer() const;
96 
102  ProgressBarRenderer* getRenderer();
103  const ProgressBarRenderer* getRenderer() const;
104 
105 
112  void setSize(const Layout2d& size) override;
113  using Widget::setSize;
114 
115 
124  void setMinimum(unsigned int minimum);
125 
126 
133  unsigned int getMinimum() const;
134 
135 
144  void setMaximum(unsigned int maximum);
145 
146 
153  unsigned int getMaximum() const;
154 
155 
164  void setValue(unsigned int value);
165 
166 
173  unsigned int getValue() const;
174 
175 
184  unsigned int incrementValue();
185 
186 
195  void setText(const sf::String& text);
196 
197 
204  const sf::String& getText() const;
205 
206 
214  void setTextSize(unsigned int size);
215 
216 
223  unsigned int getTextSize() const;
224 
225 
234  void setFillDirection(FillDirection direction);
235 
236 
245  FillDirection getFillDirection() const;
246 
247 
255  void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
256 
257 
259  protected:
260 
270  Signal& getSignal(std::string signalName) override;
271 
272 
279  void rendererChanged(const std::string& property) override;
280 
281 
283  // Returns the size without the borders
285  sf::Vector2f getInnerSize() const;
286 
287 
289  // When the value changes, or when the minimum/maximum limits change then a smaller of bigger piece of the front image
290  // must be drawn. This function is called to calculate the size of the piece to draw.
292  void recalculateFillSize();
293 
294 
296  // Returns the size of the front image.
298  sf::Vector2f getFrontImageSize() const;
299 
300 
302  // Makes a copy of the widget
304  Widget::Ptr clone() const override
305  {
306  return std::make_shared<ProgressBar>(*this);
307  }
308 
309 
311  public:
312 
313  SignalUInt onValueChange = {"ValueChanged"};
314  Signal onFull = {"Full"};
315 
316 
318  protected:
319 
320  unsigned int m_minimum = 0;
321  unsigned int m_maximum = 100;
322  unsigned int m_value = 0;
323 
324  Text m_textBack;
325  Text m_textFront;
326  unsigned int m_textSize = 0;
327 
328  sf::FloatRect m_backRect;
329  sf::FloatRect m_frontRect;
330 
331  FillDirection m_fillDirection = FillDirection::LeftToRight;
332 
333  Sprite m_spriteBackground;
334  Sprite m_spriteFill;
335 
336  // Cached renderer properties
337  Borders m_bordersCached;
338  Color m_borderColorCached;
339  Color m_backgroundColorCached;
340  Color m_fillColorCached;
341  };
342 
343 
345 }
346 
348 
349 #endif // TGUI_PROGRESS_BAR_HPP
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Definition: Sprite.hpp:40
std::shared_ptr< const ProgressBar > ConstPtr
Shared constant widget pointer.
Definition: ProgressBar.hpp:46
Wrapper for colors.
Definition: Color.hpp:46
Progress bar widget.
Definition: ProgressBar.hpp:41
Class to store the position or size of a widget.
Definition: Layout.hpp:243
Definition: ProgressBarRenderer.hpp:36
Definition: Text.hpp:41
Clickable widget.
Definition: ClickableWidget.hpp:39
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:66
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:59
std::shared_ptr< ProgressBar > Ptr
Shared widget pointer.
Definition: ProgressBar.hpp:45
FillDirection
The fill direction of the progress bar.
Definition: ProgressBar.hpp:55
Definition: Outline.hpp:38
Widget::Ptr clone() const override
Makes a copy of the widget if you don&#39;t know its exact type.
Definition: ProgressBar.hpp:304