JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
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
30 : progress { progress_ },
31 style { style_ }
32{
33}
34
36 : progress { progress_ }
37{
38}
39
40//==============================================================================
42{
43 displayPercentage = shouldDisplayPercentage;
44 repaint();
45}
46
48{
49 displayPercentage = false;
50 displayedMessage = text;
51}
52
58
60{
61 return style.value_or (getLookAndFeel().getDefaultProgressBarStyle (*this));
62}
63
65{
66 setOpaque (getLookAndFeel().isProgressBarOpaque (*this));
67}
68
74
76{
77 String text;
78
79 if (displayPercentage)
80 {
81 if (currentValue >= 0 && currentValue <= 1.0)
82 text << roundToInt (currentValue * 100.0) << '%';
83 }
84 else
85 {
86 text = displayedMessage;
87 }
88
89 const auto w = getWidth();
90 const auto h = getHeight();
91 const auto v = currentValue;
92
93 getLookAndFeel().drawProgressBar (g, *this, w, h, v, text);
94}
95
97{
98 if (isVisible())
99 startTimer (30);
100 else
101 stopTimer();
102}
103
104void ProgressBar::timerCallback()
105{
106 double newProgress = progress;
107
109 const int timeSinceLastCallback = (int) (now - lastCallbackTime);
110 lastCallbackTime = now;
111
112 if (! approximatelyEqual (currentValue, newProgress)
114 || currentMessage != displayedMessage)
115 {
116 if (currentValue < newProgress
117 && newProgress >= 0 && newProgress < 1.0
118 && currentValue >= 0 && currentValue < 1.0)
119 {
120 newProgress = jmin (currentValue + 0.0008 * timeSinceLastCallback,
122 }
123
124 currentValue = newProgress;
125 currentMessage = displayedMessage;
126 repaint();
127
128 if (auto* handler = getAccessibilityHandler())
129 handler->notifyAccessibilityEvent (AccessibilityEvent::valueChanged);
130 }
131}
132
133//==============================================================================
135{
137 {
138 public:
139 explicit ProgressBarAccessibilityHandler (ProgressBar& progressBarToWrap)
140 : AccessibilityHandler (progressBarToWrap,
141 AccessibilityRole::progressBar,
143 AccessibilityHandler::Interfaces { std::make_unique<ValueInterface> (progressBarToWrap) }),
144 progressBar (progressBarToWrap)
145 {
146 }
147
148 String getHelp() const override { return progressBar.getTooltip(); }
149
150 private:
151 class ValueInterface final : public AccessibilityRangedNumericValueInterface
152 {
153 public:
154 explicit ValueInterface (ProgressBar& progressBarToWrap)
155 : progressBar (progressBarToWrap)
156 {
157 }
158
159 bool isReadOnly() const override { return true; }
160 void setValue (double) override { jassertfalse; }
161 double getCurrentValue() const override { return progressBar.progress; }
162 AccessibleValueRange getRange() const override { return { { 0.0, 1.0 }, 0.001 }; }
163
164 private:
165 ProgressBar& progressBar;
166
167 //==============================================================================
169 };
170
171 ProgressBar& progressBar;
172
173 //==============================================================================
174 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProgressBarAccessibilityHandler)
175 };
176
177 return std::make_unique<ProgressBarAccessibilityHandler> (*this);
178}
179
180} // namespace juce
A simple wrapper for building a collection of supported accessibility actions and corresponding callb...
Base class for accessible Components.
A value interface that represents a ranged numeric value.
bool isVisible() const noexcept
Tests whether the component is visible or not.
int getHeight() const noexcept
Returns the component's height in pixels.
AccessibilityHandler * getAccessibilityHandler()
Returns the accessibility handler for this component, or nullptr if this component is not accessible.
void setOpaque(bool shouldBeOpaque)
Indicates whether any parts of the component might be transparent.
void repaint()
Marks the whole component as needing to be redrawn.
int getWidth() const noexcept
Returns the component's width in pixels.
LookAndFeel & getLookAndFeel() const noexcept
Finds the appropriate look-and-feel to use for this component.
A graphics context, used for drawing a component or image.
A progress bar component.
Style getResolvedStyle() const
Returns the progress bar's current style if it has one, or a default style determined by the look-and...
ProgressBar(double &progress)
Creates a ProgressBar.
void lookAndFeelChanged() override
Called to let the component react to a change in the look-and-feel setting.
void colourChanged() override
This method is called when a colour is changed by the setColour() method, or when the look-and-feel i...
Style
The types of ProgressBar styles available.
void setStyle(std::optional< Style > newStyle)
Sets the progress bar's current style.
void paint(Graphics &) override
Components can override this method to draw their content.
std::unique_ptr< AccessibilityHandler > createAccessibilityHandler() override
Override this method to return a custom AccessibilityHandler for this component.
void setPercentageDisplay(bool shouldDisplayPercentage)
Turns the percentage display on or off.
void visibilityChanged() override
Called when this component's visibility changes.
void setTextToDisplay(const String &text)
Gives the progress bar a string to display inside it.
The JUCE String class!
Definition juce_String.h:53
static uint32 getMillisecondCounter() noexcept
Returns the number of millisecs since a fixed event (usually system startup).
void stopTimer() noexcept
Stops the timer.
void startTimer(int intervalInMilliseconds) noexcept
Starts the timer and sets the length of interval required.
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
This is a shorthand way of writing both a JUCE_DECLARE_NON_COPYABLE and JUCE_LEAK_DETECTOR macro for ...
#define jassertfalse
This will always cause an assertion failure.
typedef int
JUCE Namespace.
constexpr bool approximatelyEqual(Type a, Type b, Tolerance< Type > tolerance=Tolerance< Type >{} .withAbsolute(std::numeric_limits< Type >::min()) .withRelative(std::numeric_limits< Type >::epsilon()))
Returns true if the two floating-point numbers are approximately equal.
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
@ valueChanged
Indicates that the UI element's value has changed.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
unsigned int uint32
A platform-independent 32-bit unsigned integer type.
int roundToInt(const FloatType value) noexcept
Fast floating-point-to-integer conversion.
Utility struct which holds one or more accessibility interfaces.
virtual void drawProgressBar(Graphics &, ProgressBar &, int width, int height, double progress, const String &textToShow)=0
Draws a progress bar.
T value_or(T... args)