|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- /*
- ==============================================================================
-
- This file is part of the JUCE library.
- Copyright (c) 2015 - ROLI Ltd.
-
- Permission is granted to use this software under the terms of either:
- a) the GPL v2 (or any later version)
- b) the Affero GPL v3
-
- Details of these licenses can be found at: www.gnu.org/licenses
-
- JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- ------------------------------------------------------------------------------
-
- To release a closed-source product which uses JUCE, commercial licenses are
- available: visit www.juce.com for more information.
-
- ==============================================================================
- */
-
- ProgressBar::ProgressBar (double& progress_)
- : progress (progress_),
- displayPercentage (true),
- lastCallbackTime (0)
- {
- currentValue = jlimit (0.0, 1.0, progress);
- }
-
- ProgressBar::~ProgressBar()
- {
- }
-
- //==============================================================================
- void ProgressBar::setPercentageDisplay (const bool shouldDisplayPercentage)
- {
- displayPercentage = shouldDisplayPercentage;
- repaint();
- }
-
- void ProgressBar::setTextToDisplay (const String& text)
- {
- displayPercentage = false;
- displayedMessage = text;
- }
-
- void ProgressBar::lookAndFeelChanged()
- {
- setOpaque (findColour (backgroundColourId).isOpaque());
- }
-
- void ProgressBar::colourChanged()
- {
- lookAndFeelChanged();
- }
-
- void ProgressBar::paint (Graphics& g)
- {
- String text;
-
- if (displayPercentage)
- {
- if (currentValue >= 0 && currentValue <= 1.0)
- text << roundToInt (currentValue * 100.0) << '%';
- }
- else
- {
- text = displayedMessage;
- }
-
- getLookAndFeel().drawProgressBar (g, *this,
- getWidth(), getHeight(),
- currentValue, text);
- }
-
- void ProgressBar::visibilityChanged()
- {
- if (isVisible())
- startTimer (30);
- else
- stopTimer();
- }
-
- void ProgressBar::timerCallback()
- {
- double newProgress = progress;
-
- const uint32 now = Time::getMillisecondCounter();
- const int timeSinceLastCallback = (int) (now - lastCallbackTime);
- lastCallbackTime = now;
-
- if (currentValue != newProgress
- || newProgress < 0 || newProgress >= 1.0
- || currentMessage != displayedMessage)
- {
- if (currentValue < newProgress
- && newProgress >= 0 && newProgress < 1.0
- && currentValue >= 0 && currentValue < 1.0)
- {
- newProgress = jmin (currentValue + 0.0008 * timeSinceLastCallback,
- newProgress);
- }
-
- currentValue = newProgress;
- currentMessage = displayedMessage;
- repaint();
- }
- }
|