BsGUIProgressBar.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #pragma once
  2. #include "BsPrerequisites.h"
  3. #include "BsGUIElementContainer.h"
  4. #include "BsEvent.h"
  5. namespace BansheeEngine
  6. {
  7. /**
  8. * @brief Contains a background image and a fill image that
  9. * is scaled depending on the percentage set by the user.
  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 layoutOptions Options that allows you to control how is the element positioned in
  38. * GUI layout. 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& layoutOptions, 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);
  58. /**
  59. * @copydoc GUIElementContainer::_getOptimalSize
  60. */
  61. virtual Vector2I _getOptimalSize() const;
  62. Event<void(float percent)> onChanged;
  63. protected:
  64. GUIProgressBar(const String& styleName, const GUILayoutOptions& layoutOptions);
  65. /**
  66. * @copydoc GUIElementContainer::_getOptimalSize
  67. */
  68. virtual void _updateLayoutInternal(INT32 x, INT32 y, UINT32 width, UINT32 height,
  69. Rect2I clipRect, UINT8 widgetDepth, UINT16 areaDepth);
  70. /**
  71. * @copydoc GUIElementContainer::styleUpdated
  72. */
  73. void styleUpdated();
  74. private:
  75. GUITexture* mBar;
  76. GUITexture* mBackground;
  77. float mPercent;
  78. };
  79. }