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.

juce_ProgressBar.h 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. */
  34. class JUCE_API ProgressBar : public Component,
  35. public SettableTooltipClient,
  36. private Timer
  37. {
  38. public:
  39. //==============================================================================
  40. /** Creates a ProgressBar.
  41. @param progress pass in a reference to a double that you're going to
  42. update with your task's progress. The ProgressBar will
  43. monitor the value of this variable and will redraw itself
  44. when the value changes. The range is from 0 to 1.0 and JUCE
  45. LookAndFeel classes will draw a spinning animation for values
  46. outside this range. Obviously you'd better be careful not to
  47. delete this variable while the ProgressBar still exists!
  48. */
  49. explicit ProgressBar (double& progress);
  50. /** Destructor. */
  51. ~ProgressBar();
  52. //==============================================================================
  53. /** Turns the percentage display on or off.
  54. By default this is on, and the progress bar will display a text string showing
  55. its current percentage.
  56. */
  57. void setPercentageDisplay (bool shouldDisplayPercentage);
  58. /** Gives the progress bar a string to display inside it.
  59. If you call this, it will turn off the percentage display.
  60. @see setPercentageDisplay
  61. */
  62. void setTextToDisplay (const String& text);
  63. //==============================================================================
  64. /** A set of colour IDs to use to change the colour of various aspects of the bar.
  65. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  66. methods.
  67. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  68. */
  69. enum ColourIds
  70. {
  71. backgroundColourId = 0x1001900, /**< The background colour, behind the bar. */
  72. foregroundColourId = 0x1001a00, /**< The colour to use to draw the bar itself. LookAndFeel
  73. classes will probably use variations on this colour. */
  74. };
  75. //==============================================================================
  76. /** This abstract base class is implemented by LookAndFeel classes. */
  77. struct JUCE_API LookAndFeelMethods
  78. {
  79. virtual ~LookAndFeelMethods() {}
  80. /** Draws a progress bar.
  81. If the progress value is less than 0 or greater than 1.0, this should draw a spinning
  82. bar that fills the whole space (i.e. to say that the app is still busy but the progress
  83. isn't known). It can use the current time as a basis for playing an animation.
  84. (Used by progress bars in AlertWindow).
  85. */
  86. virtual void drawProgressBar (Graphics&, ProgressBar&, int width, int height,
  87. double progress, const String& textToShow) = 0;
  88. virtual bool isProgressBarOpaque (ProgressBar&) = 0;
  89. };
  90. protected:
  91. //==============================================================================
  92. /** @internal */
  93. void paint (Graphics&) override;
  94. /** @internal */
  95. void lookAndFeelChanged() override;
  96. /** @internal */
  97. void visibilityChanged() override;
  98. /** @internal */
  99. void colourChanged() override;
  100. private:
  101. double& progress;
  102. double currentValue;
  103. bool displayPercentage;
  104. String displayedMessage, currentMessage;
  105. uint32 lastCallbackTime;
  106. void timerCallback() override;
  107. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProgressBar)
  108. };
  109. } // namespace juce