LMMS
Loading...
Searching...
No Matches
juce_ProgressBar.cpp
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
29ProgressBar::ProgressBar (double& progress_)
30 : progress (progress_),
33{
34 currentValue = jlimit (0.0, 1.0, progress);
35}
36
40
41//==============================================================================
42void ProgressBar::setPercentageDisplay (const bool shouldDisplayPercentage)
43{
44 displayPercentage = shouldDisplayPercentage;
45 repaint();
46}
47
53
55{
56 setOpaque (getLookAndFeel().isProgressBarOpaque (*this));
57}
58
63
65{
67
69 {
70 if (currentValue >= 0 && currentValue <= 1.0)
71 text << roundToInt (currentValue * 100.0) << '%';
72 }
73 else
74 {
76 }
77
78 getLookAndFeel().drawProgressBar (g, *this,
81}
82
84{
85 if (isVisible())
86 startTimer (30);
87 else
88 stopTimer();
89}
90
92{
93 double newProgress = progress;
94
96 const int timeSinceLastCallback = (int) (now - lastCallbackTime);
97 lastCallbackTime = now;
98
99 if (currentValue != newProgress
100 || newProgress < 0 || newProgress >= 1.0
102 {
103 if (currentValue < newProgress
104 && newProgress >= 0 && newProgress < 1.0
105 && currentValue >= 0 && currentValue < 1.0)
106 {
107 newProgress = jmin (currentValue + 0.0008 * timeSinceLastCallback,
108 newProgress);
109 }
110
111 currentValue = newProgress;
113 repaint();
114
115 if (auto* handler = getAccessibilityHandler())
116 handler->notifyAccessibilityEvent (AccessibilityEvent::valueChanged);
117 }
118}
119
120//==============================================================================
121std::unique_ptr<AccessibilityHandler> ProgressBar::createAccessibilityHandler()
122{
123 class ProgressBarAccessibilityHandler : public AccessibilityHandler
124 {
125 public:
126 explicit ProgressBarAccessibilityHandler (ProgressBar& progressBarToWrap)
127 : AccessibilityHandler (progressBarToWrap,
130 AccessibilityHandler::Interfaces { std::make_unique<ValueInterface> (progressBarToWrap) }),
131 progressBar (progressBarToWrap)
132 {
133 }
134
135 String getHelp() const override { return progressBar.getTooltip(); }
136
137 private:
138 class ValueInterface : public AccessibilityRangedNumericValueInterface
139 {
140 public:
141 explicit ValueInterface (ProgressBar& progressBarToWrap)
142 : progressBar (progressBarToWrap)
143 {
144 }
145
146 bool isReadOnly() const override { return true; }
147 void setValue (double) override { jassertfalse; }
148 double getCurrentValue() const override { return progressBar.progress; }
149 AccessibleValueRange getRange() const override { return { { 0.0, 1.0 }, 0.001 }; }
150
151 private:
153
154 //==============================================================================
156 };
157
159
160 //==============================================================================
161 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProgressBarAccessibilityHandler)
162 };
163
164 return std::make_unique<ProgressBarAccessibilityHandler> (*this);
165}
166
167} // namespace juce
Type jmin(const Type a, const Type b)
Definition MathsFunctions.h:60
Definition juce_AccessibilityActions.h:73
Definition juce_AccessibilityHandler.h:41
Definition juce_AccessibilityValueInterface.h:198
bool isVisible() const noexcept
Definition juce_Component.h:122
int getHeight() const noexcept
Definition juce_Component.h:274
AccessibilityHandler * getAccessibilityHandler()
Definition juce_Component.cpp:3302
void setOpaque(bool shouldBeOpaque)
Definition juce_Component.cpp:829
void repaint()
Definition juce_Component.cpp:1917
int getWidth() const noexcept
Definition juce_Component.h:271
LookAndFeel & getLookAndFeel() const noexcept
Definition juce_Component.cpp:2173
Definition juce_GraphicsContext.h:45
String currentMessage
Definition juce_ProgressBar.h:135
double currentValue
Definition juce_ProgressBar.h:133
bool displayPercentage
Definition juce_ProgressBar.h:134
ProgressBar(double &progress)
Definition juce_ProgressBar.cpp:29
void lookAndFeelChanged() override
Definition juce_ProgressBar.cpp:54
void colourChanged() override
Definition juce_ProgressBar.cpp:59
double & progress
Definition juce_ProgressBar.h:132
uint32 lastCallbackTime
Definition juce_ProgressBar.h:136
void timerCallback() override
Definition juce_ProgressBar.cpp:91
void paint(Graphics &) override
Definition juce_ProgressBar.cpp:64
std::unique_ptr< AccessibilityHandler > createAccessibilityHandler() override
Definition juce_ProgressBar.cpp:121
void setPercentageDisplay(bool shouldDisplayPercentage)
Definition juce_ProgressBar.cpp:42
String displayedMessage
Definition juce_ProgressBar.h:135
void visibilityChanged() override
Definition juce_ProgressBar.cpp:83
void setTextToDisplay(const String &text)
Definition juce_ProgressBar.cpp:48
~ProgressBar() override
Definition juce_ProgressBar.cpp:37
Definition juce_String.h:53
static uint32 getMillisecondCounter() noexcept
Definition juce_Time.cpp:241
void stopTimer() noexcept
Definition juce_Timer.cpp:357
void startTimer(int intervalInMilliseconds) noexcept
Definition juce_Timer.cpp:332
int g
Definition inflate.c:1573
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
#define jassertfalse
Definition carla_juce.cpp:31
unsigned int uint32
Definition juce_MathsFunctions.h:45
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
Definition juce_MathsFunctions.h:262
@ valueChanged
Definition juce_AccessibilityEvent.h:44
int roundToInt(const FloatType value) noexcept
Definition juce_MathsFunctions.h:465
@ progressBar
Definition juce_AccessibilityRole.h:60
#define true
Definition ordinals.h:82
Definition juce_AccessibilityHandler.h:49
const char * text
Definition swell-functions.h:167
void handler(int signal)
Definition fileio.c:1632
typedef int(UZ_EXP MsgFn)()