Hi,
I’m currently on the latest version on Big Sur (11.4) with the latest JUCE (6.0.8). I was implementing some level meters in my plugin when I found an issue related to the repaint function.
So, my plugin has a parent component (the Editor) with 6 children. Each children has some buttons and sliders. In one of these children there are 4 additional grand-children, the level meters.
These meters are updated periodically with a Timer placed in their parent. At each timer callback I call their repaint function.
This is the meter class, I’ve removed all the code related to the meter itself, leaving only the background, which is a simple black rectangle that covers all the available space of the component.
#pragma once
class MeterComponent : public Component
{
public:
MeterComponent()
{
setOpaque(true);
}
~MeterComponent() override
{
}
void paint (juce::Graphics& g) override
{
g.fillAll(Colours::black);
}
void resized() override
{
}
private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MeterComponent)
};
As you can see it is extremely simple. I have set setOpaque(true)
because I don’t want to repaint the whole UI, but only the meters. If I add only one meter, everything works fine, but when I add the second one (and then the third and the fourth), it starts to repaint also their parent and therefore also the Editor, causing a complete UI repaint.
I suppose that the problem is related to the fact that the “dirty” area is not only the meters, but a single big rectangle. Since the meters are on the sides of the UI, this rectangle is really wide and triggers the repaint of the parent.
I’ve read several past thread about this problem, but I couldn’t find a solution (also most of them are very old).
What is the correct way to repaint level meters 30 times a second without repainting the whole UI every time? I just need a way to disable, if it is possible, the creation of the unified rectangle, because it leads just to a waste of CPU.
Thank you.