Hi,
I’m attempting to improve the painting performance in a standalone app. My first step is to ensure that as many children become opaque. However, it appears that even when opaque children are repainted, the parent paint method is still invoked. The JUCE documentation states that “objects underneath opaque windows don’t need to be painted ,” leading me to assume that when children are repainted, the parent is not. However, upon enabling JUCE_ENABLE_REPAINT_DEBUGGING, I observed that the parent is indeed repainted when an opaque child undergoes repainting. Additionally, I’ve created a small example that logs the paint calls.
class MainComponent : public juce::Component
{
public:
MainComponent()
{
setSize (600, 400);
addAndMakeVisible(rect);
rect.setBounds(getLocalBounds().reduced(50));
}
void paint (juce::Graphics& g) override
{
DBG(juce::Time::getCurrentTime().toString(false, true) << " --- MainComponent::paint");
g.fillAll (getLookAndFeel().findColour (juce::ResizableWindow::backgroundColourId));
}
struct Rect : juce::Component, juce::Timer
{
Rect()
{
setOpaque(true);
startTimerHz(1);
}
void paint(juce::Graphics& g) override
{
DBG(juce::Time::getCurrentTime().toString(false, true) << " --- Rect::paint");
g.fillAll(juce::Colours::white);
}
void timerCallback() override
{
repaint();
}
};
Rect rect;
};
Output:
3:27:58pm --- MainComponent::paint
3:27:58pm --- Rect::paint
3:27:59pm --- MainComponent::paint
3:27:59pm --- Rect::paint
3:28:00pm --- MainComponent::paint
3:28:00pm --- Rect::paint
3:28:01pm --- MainComponent::paint
3:28:01pm --- Rect::paint
3:28:02pm --- MainComponent::paint
3:28:02pm --- Rect::paint
I run this with JUCE 7.0.9 on an Apple M1 machine with macOS 14.2.1
Is this expected behaviour?
Best,
Jelle