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.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. #pragma once
  20. //==============================================================================
  21. /**
  22. A progress bar component.
  23. To use this, just create one and make it visible. It'll run its own timer
  24. to keep an eye on a variable that you give it, and will automatically
  25. redraw itself when the variable changes.
  26. For an easy way of running a background task with a dialog box showing its
  27. progress, see the ThreadWithProgressWindow class.
  28. @see ThreadWithProgressWindow
  29. */
  30. class JUCE_API ProgressBar : public Component,
  31. public SettableTooltipClient,
  32. private Timer
  33. {
  34. public:
  35. //==============================================================================
  36. /** Creates a ProgressBar.
  37. @param progress pass in a reference to a double that you're going to
  38. update with your task's progress. The ProgressBar will
  39. monitor the value of this variable and will redraw itself
  40. when the value changes. The range is from 0 to 1.0. Obviously
  41. you'd better be careful not to delete this variable while the
  42. ProgressBar still exists!
  43. */
  44. explicit ProgressBar (double& progress);
  45. /** Destructor. */
  46. ~ProgressBar();
  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() {}
  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. };