BsGUIProgressBar.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #pragma once
  2. #include "BsPrerequisites.h"
  3. #include "BsGUIElementContainer.h"
  4. #include "BsEvent.h"
  5. namespace BansheeEngine
  6. {
  7. /**
  8. * @brief GUI element containing a background image and a fill image that
  9. * is scaled depending on the percentage set by the caller.
  10. */
  11. class BS_EXPORT GUIProgressBar : public GUIElementContainer
  12. {
  13. public:
  14. /**
  15. * Returns type name of the GUI element used for finding GUI element styles.
  16. */
  17. static const String& getGUITypeName();
  18. /**
  19. * @brief Name of the style for the fill image used by the progress bar.
  20. */
  21. static const String& getBarStyleType();
  22. /**
  23. * @brief Name of the style for the background image used by the progress bar.
  24. */
  25. static const String& getBackgroundStyleType();
  26. /**
  27. * @brief Creates a new progress bar.
  28. *
  29. * @param styleName Optional style to use for the element. Style will be retrieved
  30. * from GUISkin of the GUIWidget the element is used on. If not specified
  31. * default style is used.
  32. */
  33. static GUIProgressBar* create(const String& styleName = StringUtil::BLANK);
  34. /**
  35. * @brief Creates a new progress bar.
  36. *
  37. * @param options Options that allow you to control how is the element positioned and sized.
  38. * This will override any similar options set by style.
  39. * @param styleName Optional style to use for the element. Style will be retrieved
  40. * from GUISkin of the GUIWidget the element is used on. If not specified
  41. * default style is used.
  42. */
  43. static GUIProgressBar* create(const GUIOptions& options, const String& styleName = StringUtil::BLANK);
  44. /**
  45. * @brief Fills up the progress bar up to the specified percentage.
  46. *
  47. * @param pct How far to extend the fill image, in percent ranging [0.0f, 1.0f]
  48. */
  49. void setPercent(float pct);
  50. /**
  51. * @brief Gets the percentage of how full is the progress bar currently.
  52. */
  53. float getPercent() const { return mPercent; }
  54. /**
  55. * @copydoc GUIElement::setTint
  56. */
  57. virtual void setTint(const Color& color) override;
  58. /**
  59. * @copydoc GUIElementContainer::_getOptimalSize
  60. */
  61. virtual Vector2I _getOptimalSize() const override;
  62. Event<void(float percent)> onChanged;
  63. protected:
  64. GUIProgressBar(const String& styleName, const GUIDimensions& dimensions);
  65. /**
  66. * @copydoc GUIElementContainer::_updateLayoutInternal
  67. */
  68. virtual void _updateLayoutInternal(const GUILayoutData& data) override;
  69. /**
  70. * @copydoc GUIElementContainer::styleUpdated
  71. */
  72. void styleUpdated() override;
  73. private:
  74. GUITexture* mBar;
  75. GUITexture* mBackground;
  76. float mPercent;
  77. };
  78. }