TGUI  0.7.4
ProgressBar.hpp
1 //
3 // TGUI - Texus's 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/Widgets/Label.hpp>
31 
33 
34 namespace tgui
35 {
36  class ProgressBarRenderer;
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 
79  ProgressBar();
80 
81 
88  static ProgressBar::Ptr create();
89 
90 
99  static ProgressBar::Ptr copy(ProgressBar::ConstPtr progressBar);
100 
101 
108  std::shared_ptr<ProgressBarRenderer> getRenderer() const
109  {
110  return std::static_pointer_cast<ProgressBarRenderer>(m_renderer);
111  }
112 
113 
126  virtual void setPosition(const Layout2d& position) override;
128 
129 
136  void setSize(const Layout2d& size) override;
138 
139 
148  virtual sf::Vector2f getFullSize() const override;
149 
150 
159  virtual void setFont(const Font& font) override;
160 
161 
170  void setMinimum(unsigned int minimum);
171 
172 
181  void setMaximum(unsigned int maximum);
182 
183 
192  void setValue(unsigned int value);
193 
194 
201  unsigned int getMinimum() const
202  {
203  return m_minimum;
204  }
205 
206 
213  unsigned int getMaximum() const
214  {
215  return m_maximum;
216  }
217 
218 
225  unsigned int getValue() const
226  {
227  return m_value;
228  }
229 
230 
239  unsigned int incrementValue();
240 
241 
250  void setText(const sf::String& text);
251 
252 
259  sf::String getText() const
260  {
261  return m_textBack.getText();
262  }
263 
264 
272  void setTextSize(unsigned int size);
273 
274 
281  unsigned int getTextSize() const
282  {
283  return m_textBack.getTextSize();
284  }
285 
286 
295  void setFillDirection(FillDirection direction);
296 
297 
307  {
308  return m_fillDirection;
309  }
310 
311 
318  virtual void setOpacity(float opacity) override;
319 
320 
329  virtual sf::Vector2f getWidgetOffset() const override;
330 
331 
333  protected:
334 
347  virtual void reload(const std::string& primary = "", const std::string& secondary = "", bool force = false) override;
348 
349 
351  // Makes a copy of the widget
353  virtual Widget::Ptr clone() const override
354  {
355  return std::make_shared<ProgressBar>(*this);
356  }
357 
358 
360  // When the value changes, or when the minimum/maximum limits change then a smaller of bigger piece of the front image
361  // must be drawn. This function is called to calculate the size of the piece to draw.
363  void recalculateSize();
364 
365 
367  // Draws the widget on the render target.
369  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
370 
371 
373  protected:
374 
375  unsigned int m_minimum = 0;
376  unsigned int m_maximum = 100;
377  unsigned int m_value = 0;
378 
379  Label m_textBack;
380  Label m_textFront;
381  unsigned int m_textSize = 0;
382 
383  sf::FloatRect m_frontRect;
384 
385  FillDirection m_fillDirection = FillDirection::LeftToRight;
386 
387  friend class ProgressBarRenderer;
388  };
389 
390 
392 
393  class TGUI_API ProgressBarRenderer : public WidgetRenderer, public WidgetBorders
394  {
395  public:
396 
403  ProgressBarRenderer(ProgressBar* progressBar) : m_progressBar{progressBar} {}
404 
405 
415  virtual void setProperty(std::string property, const std::string& value) override;
416 
417 
428  virtual void setProperty(std::string property, ObjectConverter&& value) override;
429 
430 
440  virtual ObjectConverter getProperty(std::string property) const override;
441 
442 
449  virtual std::map<std::string, ObjectConverter> getPropertyValuePairs() const override;
450 
451 
461  void setTextFont(std::shared_ptr<sf::Font> font);
462 
463 
475  void setTextColor(const Color& color);
476 
477 
486  void setTextColorBack(const Color& color);
487 
488 
497  void setTextColorFront(const Color& color);
498 
499 
510  void setBackgroundColor(const Color& color);
511 
512 
523  void setForegroundColor(const Color& color);
524 
525 
532  void setBorderColor(const Color& color);
533 
534 
544  void setBackTexture(const Texture& texture);
545 
546 
556  void setFrontTexture(const Texture& texture);
557 
558 
560  // Draws the widget on the render target.
562  void draw(sf::RenderTarget& target, sf::RenderStates states) const;
563 
564 
566  private:
567 
569  // Makes a copy of the renderer
571  virtual std::shared_ptr<WidgetRenderer> clone(Widget* widget) override;
572 
573 
575  protected:
576 
577  ProgressBar* m_progressBar;
578 
579  Texture m_textureBack;
580  Texture m_textureFront;
581 
582  sf::Color m_textColorFront;
583  sf::Color m_textColorBack;
584 
585  sf::Color m_backgroundColor;
586  sf::Color m_foregroundColor;
587 
588  sf::Color m_borderColor;
589 
590  friend class ProgressBar;
591 
593  };
594 
596 }
597 
599 
600 #endif // TGUI_PROGRESS_BAR_HPP
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:33
std::shared_ptr< const ProgressBar > ConstPtr
Shared constant widget pointer.
Definition: ProgressBar.hpp:58
Implicit converter for colors.
Definition: Color.hpp:39
Progress bar widget.
Definition: ProgressBar.hpp:53
unsigned int getValue() const
Returns the current value.
Definition: ProgressBar.hpp:225
Definition: Font.hpp:37
Class to store the position or size of a widget.
Definition: Layout.hpp:262
Label widget.
Definition: Label.hpp:49
The parent class for every widget.
Definition: Widget.hpp:71
Definition: ProgressBar.hpp:393
unsigned int getMinimum() const
Returns the minimum value.
Definition: ProgressBar.hpp:201
FillDirection getFillDirection()
Returns the fill direction of the progress bar.
Definition: ProgressBar.hpp:306
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
virtual void setPosition(const Layout2d &position)
set the position of the widget
Clickable widget.
Definition: ClickableWidget.hpp:55
Parent class for every widget that has borders.
Definition: Borders.hpp:136
Implicit converter for settable properties.
Definition: ObjectConverter.hpp:42
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:75
unsigned int getMaximum() const
Returns the maximum value.
Definition: ProgressBar.hpp:213
Definition: Texture.hpp:44
ProgressBarRenderer(ProgressBar *progressBar)
Constructor.
Definition: ProgressBar.hpp:403
std::shared_ptr< ProgressBar > Ptr
Shared widget pointer.
Definition: ProgressBar.hpp:57
std::shared_ptr< ProgressBarRenderer > getRenderer() const
Returns the renderer, which gives access to functions that determine how the widget is displayed...
Definition: ProgressBar.hpp:108
FillDirection
The fill direction of the progress bar.
Definition: ProgressBar.hpp:67
unsigned int getTextSize() const
Returns the character size of the text.
Definition: ProgressBar.hpp:281
sf::String getText() const
Returns the caption of the progress bar.
Definition: ProgressBar.hpp:259
virtual Widget::Ptr clone() const override
Makes a copy of the widget if you don&#39;t know its exact type.
Definition: ProgressBar.hpp:353
Base class for all renderer classes.
Definition: Widget.hpp:682