TGUI  0.8-beta
ProgressBar.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2018 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 
252  bool mouseOnWidget(Vector2f pos) const override;
253 
254 
262  void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
263 
264 
266  protected:
267 
277  Signal& getSignal(std::string signalName) override;
278 
279 
286  void rendererChanged(const std::string& property) override;
287 
288 
292  std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
293 
294 
298  void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
299 
300 
302  // Returns the size without the borders
304  Vector2f getInnerSize() const;
305 
306 
308  // When the value changes, or when the minimum/maximum limits change then a smaller of bigger piece of the front image
309  // must be drawn. This function is called to calculate the size of the piece to draw.
311  void recalculateFillSize();
312 
313 
315  // Returns the size of the front image.
317  Vector2f getFrontImageSize() const;
318 
319 
321  // Makes a copy of the widget
323  Widget::Ptr clone() const override
324  {
325  return std::make_shared<ProgressBar>(*this);
326  }
327 
328 
330  public:
331 
332  SignalUInt onValueChange = {"ValueChanged"};
333  Signal onFull = {"Full"};
334 
335 
337  protected:
338 
339  unsigned int m_minimum = 0;
340  unsigned int m_maximum = 100;
341  unsigned int m_value = 0;
342 
343  Text m_textBack;
344  Text m_textFront;
345  unsigned int m_textSize = 0;
346 
347  FloatRect m_backRect;
348  FloatRect m_frontRect;
349 
350  FillDirection m_fillDirection = FillDirection::LeftToRight;
351 
352  Sprite m_spriteBackground;
353  Sprite m_spriteFill;
354 
355  // Cached renderer properties
356  Borders m_bordersCached;
357  Color m_borderColorCached;
358  Color m_backgroundColorCached;
359  Color m_fillColorCached;
360  };
361 
362 
364 }
365 
367 
368 #endif // TGUI_PROGRESS_BAR_HPP
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Definition: Sprite.hpp:43
std::shared_ptr< const ProgressBar > ConstPtr
Shared constant widget pointer.
Definition: ProgressBar.hpp:46
Wrapper for colors.
Definition: Color.hpp:47
Progress bar widget.
Definition: ProgressBar.hpp:41
Class to store the position or size of a widget.
Definition: Layout.hpp:243
Definition: Vector2f.hpp:37
Definition: ProgressBarRenderer.hpp:36
Definition: Text.hpp:42
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:76
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:58
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:323
Definition: FloatRect.hpp:36