Audio plugin host https://kx.studio/carla
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.

136 lines
5.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef JUCE_PROGRESSBAR_H_INCLUDED
  18. #define JUCE_PROGRESSBAR_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. A progress bar component.
  22. To use this, just create one and make it visible. It'll run its own timer
  23. to keep an eye on a variable that you give it, and will automatically
  24. redraw itself when the variable changes.
  25. For an easy way of running a background task with a dialog box showing its
  26. progress, see the ThreadWithProgressWindow class.
  27. @see ThreadWithProgressWindow
  28. */
  29. class JUCE_API ProgressBar : public Component,
  30. public SettableTooltipClient,
  31. private Timer
  32. {
  33. public:
  34. //==============================================================================
  35. /** Creates a ProgressBar.
  36. @param progress pass in a reference to a double that you're going to
  37. update with your task's progress. The ProgressBar will
  38. monitor the value of this variable and will redraw itself
  39. when the value changes. The range is from 0 to 1.0. Obviously
  40. you'd better be careful not to delete this variable while the
  41. ProgressBar still exists!
  42. */
  43. explicit ProgressBar (double& progress);
  44. /** Destructor. */
  45. ~ProgressBar();
  46. //==============================================================================
  47. /** Turns the percentage display on or off.
  48. By default this is on, and the progress bar will display a text string showing
  49. its current percentage.
  50. */
  51. void setPercentageDisplay (bool shouldDisplayPercentage);
  52. /** Gives the progress bar a string to display inside it.
  53. If you call this, it will turn off the percentage display.
  54. @see setPercentageDisplay
  55. */
  56. void setTextToDisplay (const String& text);
  57. //==============================================================================
  58. /** A set of colour IDs to use to change the colour of various aspects of the bar.
  59. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  60. methods.
  61. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  62. */
  63. enum ColourIds
  64. {
  65. backgroundColourId = 0x1001900, /**< The background colour, behind the bar. */
  66. foregroundColourId = 0x1001a00, /**< The colour to use to draw the bar itself. LookAndFeel
  67. classes will probably use variations on this colour. */
  68. };
  69. //==============================================================================
  70. /** This abstract base class is implemented by LookAndFeel classes. */
  71. struct JUCE_API LookAndFeelMethods
  72. {
  73. virtual ~LookAndFeelMethods() {}
  74. /** Draws a progress bar.
  75. If the progress value is less than 0 or greater than 1.0, this should draw a spinning
  76. bar that fills the whole space (i.e. to say that the app is still busy but the progress
  77. isn't known). It can use the current time as a basis for playing an animation.
  78. (Used by progress bars in AlertWindow).
  79. */
  80. virtual void drawProgressBar (Graphics&, ProgressBar&, int width, int height,
  81. double progress, const String& textToShow) = 0;
  82. };
  83. protected:
  84. //==============================================================================
  85. /** @internal */
  86. void paint (Graphics&) override;
  87. /** @internal */
  88. void lookAndFeelChanged() override;
  89. /** @internal */
  90. void visibilityChanged() override;
  91. /** @internal */
  92. void colourChanged() override;
  93. private:
  94. double& progress;
  95. double currentValue;
  96. bool displayPercentage;
  97. String displayedMessage, currentMessage;
  98. uint32 lastCallbackTime;
  99. void timerCallback() override;
  100. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProgressBar)
  101. };
  102. #endif // JUCE_PROGRESSBAR_H_INCLUDED