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