The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
5.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. namespace juce
  20. {
  21. //==============================================================================
  22. /**
  23. A progress bar component.
  24. To use this, just create one and make it visible. It'll run its own timer
  25. to keep an eye on a variable that you give it, and will automatically
  26. redraw itself when the variable changes.
  27. If using LookAndFeel_V4 a circular spinning progress bar will be drawn if
  28. the width and height of the ProgressBar are equal, otherwise the standard,
  29. linear ProgressBar will be drawn.
  30. For an easy way of running a background task with a dialog box showing its
  31. progress, see the ThreadWithProgressWindow class.
  32. @see ThreadWithProgressWindow
  33. @tags{GUI}
  34. */
  35. class JUCE_API ProgressBar : public Component,
  36. public SettableTooltipClient,
  37. private Timer
  38. {
  39. public:
  40. //==============================================================================
  41. /** Creates a ProgressBar.
  42. @param progress pass in a reference to a double that you're going to
  43. update with your task's progress. The ProgressBar will
  44. monitor the value of this variable and will redraw itself
  45. when the value changes. The range is from 0 to 1.0 and JUCE
  46. LookAndFeel classes will draw a spinning animation for values
  47. outside this range. Obviously you'd better be careful not to
  48. delete this variable while the ProgressBar still exists!
  49. */
  50. explicit ProgressBar (double& progress);
  51. /** Destructor. */
  52. ~ProgressBar();
  53. //==============================================================================
  54. /** Turns the percentage display on or off.
  55. By default this is on, and the progress bar will display a text string showing
  56. its current percentage.
  57. */
  58. void setPercentageDisplay (bool shouldDisplayPercentage);
  59. /** Gives the progress bar a string to display inside it.
  60. If you call this, it will turn off the percentage display.
  61. @see setPercentageDisplay
  62. */
  63. void setTextToDisplay (const String& text);
  64. //==============================================================================
  65. /** A set of colour IDs to use to change the colour of various aspects of the bar.
  66. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  67. methods.
  68. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  69. */
  70. enum ColourIds
  71. {
  72. backgroundColourId = 0x1001900, /**< The background colour, behind the bar. */
  73. foregroundColourId = 0x1001a00, /**< The colour to use to draw the bar itself. LookAndFeel
  74. classes will probably use variations on this colour. */
  75. };
  76. //==============================================================================
  77. /** This abstract base class is implemented by LookAndFeel classes. */
  78. struct JUCE_API LookAndFeelMethods
  79. {
  80. virtual ~LookAndFeelMethods() {}
  81. /** Draws a progress bar.
  82. If the progress value is less than 0 or greater than 1.0, this should draw a spinning
  83. bar that fills the whole space (i.e. to say that the app is still busy but the progress
  84. isn't known). It can use the current time as a basis for playing an animation.
  85. (Used by progress bars in AlertWindow).
  86. */
  87. virtual void drawProgressBar (Graphics&, ProgressBar&, int width, int height,
  88. double progress, const String& textToShow) = 0;
  89. virtual bool isProgressBarOpaque (ProgressBar&) = 0;
  90. };
  91. protected:
  92. //==============================================================================
  93. /** @internal */
  94. void paint (Graphics&) override;
  95. /** @internal */
  96. void lookAndFeelChanged() override;
  97. /** @internal */
  98. void visibilityChanged() override;
  99. /** @internal */
  100. void colourChanged() override;
  101. private:
  102. double& progress;
  103. double currentValue;
  104. bool displayPercentage;
  105. String displayedMessage, currentMessage;
  106. uint32 lastCallbackTime;
  107. void timerCallback() override;
  108. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProgressBar)
  109. };
  110. } // namespace juce