ProgressBar.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //
  2. // Copyright (c) 2008-2020 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "BorderImage.h"
  24. #include "../Math/Vector2.h"
  25. #include "Text.h"
  26. namespace Urho3D
  27. {
  28. /// %ProgressBar bar %UI element.
  29. class URHO3D_API ProgressBar : public BorderImage
  30. {
  31. URHO3D_OBJECT(ProgressBar, BorderImage);
  32. public:
  33. /// Construct.
  34. explicit ProgressBar(Context *context);
  35. /// Destruct.
  36. ~ProgressBar() override;
  37. /// Register object factory.
  38. static void RegisterObject(Context *context);
  39. /// React to resize.
  40. void OnResize(const IntVector2& newSize, const IntVector2& delta) override;
  41. /// Set orientation type.
  42. /// @property
  43. void SetOrientation(Orientation orientation);
  44. /// Set ProgressBar range maximum value (minimum value is always 0).
  45. /// @property
  46. void SetRange(float range);
  47. /// Set ProgressBar current value.
  48. /// @property
  49. void SetValue(float value);
  50. /// Change value by a delta.
  51. void ChangeValue(float delta);
  52. /// Return orientation type.
  53. /// @property
  54. Orientation GetOrientation() const { return orientation_; }
  55. /// Return ProgressBar range.
  56. /// @property
  57. float GetRange() const { return range_; }
  58. /// Return ProgressBar current value.
  59. /// @property
  60. float GetValue() const { return value_; }
  61. /// Return knob element.
  62. /// @property
  63. BorderImage *GetKnob() const { return knob_; }
  64. /// Sets the loading percent style.
  65. void SetLoadingPercentStyle(const String &style) { loadingPercentStyle_ = style; }
  66. /// Returns the loading percent style.
  67. const String& GetLoadingPercentStyle() const { return loadingPercentStyle_; }
  68. /// Sets the flag to display the percent text.
  69. /// @property
  70. void SetShowPercentText(bool enable);
  71. /// Returns the flag to display the percent text.
  72. /// @property
  73. bool GetShowPercentText() const { return showPercentText_; }
  74. protected:
  75. /// Filter implicit attributes in serialization process.
  76. bool FilterImplicitAttributes(XMLElement &dest) const override;
  77. /// Update ProgressBar knob position & size.
  78. void UpdateProgressBar();
  79. /// ProgressBar knob.
  80. SharedPtr<BorderImage> knob_;
  81. /// ProgressBar text.
  82. SharedPtr<Text> loadingText_;
  83. /// Orientation.
  84. Orientation orientation_;
  85. /// ProgressBar text style.
  86. String loadingPercentStyle_;
  87. /// ProgressBar range.
  88. float range_;
  89. /// ProgressBar current value.
  90. float value_;
  91. /// Flag to show the percent text.
  92. bool showPercentText_;
  93. };
  94. }