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 {
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 
77  // Default constructor
79  ProgressBar();
80 
81 
88  static ProgressBar::Ptr create();
89 
90 
99  static ProgressBar::Ptr copy(ProgressBar::ConstPtr progressBar);
100 
101 
109  {
110  return aurora::downcast<ProgressBarRenderer*>(m_renderer.get());
111  }
112 
113 
120  void setSize(const Layout2d& size) override;
122 
123 
132  void setMinimum(unsigned int minimum);
133 
134 
141  unsigned int getMinimum() const;
142 
143 
152  void setMaximum(unsigned int maximum);
153 
154 
161  unsigned int getMaximum() const;
162 
163 
172  void setValue(unsigned int value);
173 
174 
181  unsigned int getValue() const;
182 
183 
192  unsigned int incrementValue();
193 
194 
203  void setText(const sf::String& text);
204 
205 
212  const sf::String& getText() const;
213 
214 
222  void setTextSize(unsigned int size);
223 
224 
231  unsigned int getTextSize() const;
232 
233 
242  void setFillDirection(FillDirection direction);
243 
244 
253  FillDirection getFillDirection() const;
254 
255 
263  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
264 
265 
267  protected:
268 
275  virtual void rendererChanged(const std::string& property) override;
276 
277 
279  // Returns the size without the borders
281  sf::Vector2f getInnerSize() const;
282 
283 
285  // When the value changes, or when the minimum/maximum limits change then a smaller of bigger piece of the front image
286  // must be drawn. This function is called to calculate the size of the piece to draw.
288  void recalculateFillSize();
289 
290 
292  // Makes a copy of the widget
294  virtual Widget::Ptr clone() const override
295  {
296  return std::make_shared<ProgressBar>(*this);
297  }
298 
299 
301  protected:
302 
303  unsigned int m_minimum = 0;
304  unsigned int m_maximum = 100;
305  unsigned int m_value = 0;
306 
307  Text m_textBack;
308  Text m_textFront;
309  unsigned int m_textSize = 0;
310 
311  sf::FloatRect m_backRect;
312  sf::FloatRect m_frontRect;
313 
314  FillDirection m_fillDirection = FillDirection::LeftToRight;
315 
316  Sprite m_spriteBackground;
317  Sprite m_spriteFill;
318 
319  // Cached renderer properties
320  Borders m_bordersCached;
321  Color m_borderColorCached;
322  Color m_backgroundColorCached;
323  Color m_fillColorCached;
324  };
325 
326 
328 }
329 
331 
332 #endif // TGUI_PROGRESS_BAR_HPP
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:33
Definition: Sprite.hpp:40
std::shared_ptr< const ProgressBar > ConstPtr
Shared constant widget pointer.
Definition: ProgressBar.hpp:58
Wrapper for colors.
Definition: Color.hpp:46
Progress bar widget.
Definition: ProgressBar.hpp:53
Class to store the position or size of a widget.
Definition: Layout.hpp:263
Definition: ProgressBarRenderer.hpp:36
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
Definition: Text.hpp:41
Clickable widget.
Definition: ClickableWidget.hpp:55
ProgressBarRenderer * getRenderer() const
Returns the renderer, which gives access to functions that determine how the widget is displayed...
Definition: ProgressBar.hpp:108
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:76
std::shared_ptr< ProgressBar > Ptr
Shared widget pointer.
Definition: ProgressBar.hpp:57
FillDirection
The fill direction of the progress bar.
Definition: ProgressBar.hpp:67
Definition: Outline.hpp:37
virtual Widget::Ptr clone() const override
Makes a copy of the widget if you don&#39;t know its exact type.
Definition: ProgressBar.hpp:294