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.

121 lines
4.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_PROGRESSBAR_JUCEHEADER__
  19. #define __JUCE_PROGRESSBAR_JUCEHEADER__
  20. #include "../components/juce_Component.h"
  21. #include "../mouse/juce_TooltipClient.h"
  22. //==============================================================================
  23. /**
  24. A progress bar component.
  25. To use this, just create one and make it visible. It'll run its own timer
  26. to keep an eye on a variable that you give it, and will automatically
  27. redraw itself when the variable changes.
  28. For an easy way of running a background task with a dialog box showing its
  29. progress, see the ThreadWithProgressWindow class.
  30. @see ThreadWithProgressWindow
  31. */
  32. class JUCE_API ProgressBar : public Component,
  33. public SettableTooltipClient,
  34. private Timer
  35. {
  36. public:
  37. //==============================================================================
  38. /** Creates a ProgressBar.
  39. @param progress pass in a reference to a double that you're going to
  40. update with your task's progress. The ProgressBar will
  41. monitor the value of this variable and will redraw itself
  42. when the value changes. The range is from 0 to 1.0. Obviously
  43. you'd better be careful not to delete this variable while the
  44. ProgressBar still exists!
  45. */
  46. explicit ProgressBar (double& progress);
  47. /** Destructor. */
  48. ~ProgressBar();
  49. //==============================================================================
  50. /** Turns the percentage display on or off.
  51. By default this is on, and the progress bar will display a text string showing
  52. its current percentage.
  53. */
  54. void setPercentageDisplay (bool shouldDisplayPercentage);
  55. /** Gives the progress bar a string to display inside it.
  56. If you call this, it will turn off the percentage display.
  57. @see setPercentageDisplay
  58. */
  59. void setTextToDisplay (const String& text);
  60. //==============================================================================
  61. /** A set of colour IDs to use to change the colour of various aspects of the bar.
  62. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  63. methods.
  64. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  65. */
  66. enum ColourIds
  67. {
  68. backgroundColourId = 0x1001900, /**< The background colour, behind the bar. */
  69. foregroundColourId = 0x1001a00, /**< The colour to use to draw the bar itself. LookAndFeel
  70. classes will probably use variations on this colour. */
  71. };
  72. protected:
  73. //==============================================================================
  74. /** @internal */
  75. void paint (Graphics& g);
  76. /** @internal */
  77. void lookAndFeelChanged();
  78. /** @internal */
  79. void visibilityChanged();
  80. /** @internal */
  81. void colourChanged();
  82. private:
  83. double& progress;
  84. double currentValue;
  85. bool displayPercentage;
  86. String displayedMessage, currentMessage;
  87. uint32 lastCallbackTime;
  88. void timerCallback();
  89. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProgressBar);
  90. };
  91. #endif // __JUCE_PROGRESSBAR_JUCEHEADER__