ProgressBar.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //
  2. // Copyright (c) 2008-2017 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. ProgressBar(Context *context);
  35. /// Destruct.
  36. virtual ~ProgressBar();
  37. /// Register object factory.
  38. static void RegisterObject(Context *context);
  39. /// React to resize.
  40. virtual void OnResize(const IntVector2& newSize, const IntVector2& delta);
  41. /// Set orientation type.
  42. void SetOrientation(Orientation orientation);
  43. /// Set ProgressBar range maximum value (minimum value is always 0.)
  44. void SetRange(float range);
  45. /// Set ProgressBar current value.
  46. void SetValue(float value);
  47. /// Change value by a delta.
  48. void ChangeValue(float delta);
  49. /// Return orientation type.
  50. Orientation GetOrientation() const { return orientation_; }
  51. /// Return ProgressBar range.
  52. float GetRange() const { return range_; }
  53. /// Return ProgressBar current value.
  54. float GetValue() const { return value_; }
  55. /// Return knob element.
  56. BorderImage *GetKnob() const { return knob_; }
  57. /// Sets the loading percent style.
  58. void SetLoadingPercentStyle(const String &style) { loadingPercentStyle_ = style; }
  59. /// Returns the loading percent style.
  60. const String& GetLoadingPercentStyle() const { return loadingPercentStyle_; }
  61. /// Sets the flag to display the percent text.
  62. void SetShowPercentText(bool showPercentText);
  63. /// Returns the flag to display the percent text.
  64. bool GetShowPercentText() const { return showPercentText_; }
  65. protected:
  66. /// Filter implicit attributes in serialization process.
  67. virtual bool FilterImplicitAttributes(XMLElement &dest) const;
  68. /// Update ProgressBar knob position & size.
  69. void UpdateProgressBar();
  70. /// ProgressBar knob.
  71. SharedPtr <BorderImage> knob_;
  72. /// ProgressBar text
  73. SharedPtr <Text> loadingText_;
  74. /// Orientation.
  75. Orientation orientation_;
  76. /// ProgressBar text style
  77. String loadingPercentStyle_;
  78. /// ProgressBar range.
  79. float range_;
  80. /// ProgressBar current value.
  81. float value_;
  82. /// Flag to show the percent text.
  83. bool showPercentText_;
  84. };
  85. }