Redraw question

A1 and A2 are sibling components with the same bounds and transparent, and B1 and B2 are their respective children. B1 and B2 are opaque and have the same bounds as each other, but are smaller than their parents.

If B1 repaints will B2 repaint?

I think that if A1 is behind A2 then B1 won’t repaint, as it’s entirely occluded by B2. But would need to try it to find out…

I’ll try it. My DockableWindows seem to be redrawing even when their contents are entirely invisible …

Check this in case I’m doing it wrong … but looks like, with B2 in front:

  • B1 repainting causes B2 and B1 to repaint
  • B2 repainting causes B2 and B1 to repaint

If the Sub component is set to opaque, then calling B1.repaint() causes B2 to repaint. Not sure I can follow the logic here.

class Sub : public Component
{
public:
    Sub()
    {
        setOpaque(false);
    }
    
    void paint(Graphics&g) { DBG(getName()); g.fillAll(col.withAlpha(0.2f)); }
    
private:
    Colour col;
};

class SubSub : public Component
{
public:
    SubSub()
    {
        setOpaque(true);
    }
    
    void paint(Graphics&g)
    {
        DBG(getName());
        g.fillAll(Colours::darkgrey);
        g.setColour(Colours::white);
        g.drawText(getName(), getLocalBounds(), Justification::centred, false);
    }
    
private:
};

class MainContentComponent
: public Component
{
public:

    MainContentComponent()
    {
        setSize(200, 200);
        
        addAndMakeVisible(a1);
        addAndMakeVisible(a2);
        
        a1.addAndMakeVisible(b1);
        a2.addAndMakeVisible(b2);
        
        a1.setName("A1");
        a2.setName("A2");
        b1.setName("B1");
        b2.setName("B2");
    }

    void paint (Graphics&g) override
    {
        g.fillAll(Colours::blue);
        g.setColour(Colours::white);
        g.drawText("Click here to repaint B1", getLocalBounds().removeFromBottom(20), Justification::centred, false);
    }
    
    void mouseDown(const MouseEvent &) override
    {
        b1.repaint();
    }
    
    void resized() override
    {
        auto area = getLocalBounds().withTrimmedBottom(20);
        
        a1.setBounds(area); 
        a2.setBounds(area);
        
        b1.setBounds(area.withTrimmedBottom(20));
        b2.setBounds(area.withTrimmedBottom(20));
    }

private:
    Sub a1, a2;
    SubSub b1, b2;
};

Jules -

Is this the right behaviour?

I’ve got some transparent windows, holding content which isn’t transparent, and I’m getting a shit load of unwanted redraws as a result. If components don’t check for non-siblings occluding them then I’ll add some features to my code which makes the content component invisible when it’s hidden behind another window or something.

cheers!