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.

137 lines
5.1KB

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