# Should opaque children repaint the parent?

**URL:** <https://forum.juce.com/t/should-opaque-children-repaint-the-parent/59452>\
**Category:** General JUCE discussion\
**Created:** [January 9, 2024, 2:31pm UTC](https://forum.juce.com/t/should-opaque-children-repaint-the-parent/59452 "2024-01-09T14:31:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jellebakker](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jellebakker/32/17053_2.png) [@jellebakker](https://forum.juce.com/u/jellebakker)\
**Post date:** [January 9, 2024, 2:31pm UTC](https://forum.juce.com/t/should-opaque-children-repaint-the-parent/59452/1 "2024-01-09T14:31:34Z")

</div>

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.

```auto
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:

```auto
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

---

<div class="post-metadata">

**Author:** ![bissov](https://avatars.discourse-cdn.com/v4/letter/b/eb9ed0/32.png) [@bissov](https://forum.juce.com/u/bissov)\
**Post date:** [January 10, 2024, 2:29pm UTC](https://forum.juce.com/t/should-opaque-children-repaint-the-parent/59452/2 "2024-01-10T14:29:28Z")

</div>

Hey ! - I’ve exactly dealt with the same problem recently. But solved it with the following Preprocessor Directive “JUCE\_COREGRAPHICS\_RENDER\_WITH\_MULTIPLE\_PAINT\_CALLS=1” which I’ve included in the Jucer…

Thant solved my problem with opaque not working…

BR  
Bo

---

<div class="post-metadata">

**Author:** ![Toddler-Boy](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/toddler-boy/32/2007_2.png) [@Toddler-Boy](https://forum.juce.com/u/Toddler-Boy)\
**Post date:** [January 11, 2024, 1:23am UTC](https://forum.juce.com/t/should-opaque-children-repaint-the-parent/59452/3 "2024-01-11T01:23:02Z")

</div>

We recently also discovered that we accidentally missed this define when switching from Projucer to cmake. This caused our plugin to lag horrifically, to the point that it slowed down drawing in the DAW as well.

Once we added the definition back, the drawing became butter-smooth again. This one is a doozy and should be enabled by default, IMO.
