Hi,
Sorry to dig up an old thread, but I’m having a problem with this too. I have two components that update frequently, but for each update all the components which sit between these two (and the parent component and even the content component in the background) are redrawn each time too
The point of failure seems to be in juce_Component.cpp line 1918, where Graphics::reduceClipRegion() calls CoreGraphicsContext::clipToRectangle() which incorrectly determines that the extra components should be painted. It seems to boil down to the fact that (as Jules mentioned) when CoreGraphics is managing the clip regions there is no way to test if our component (rectangle) intersects the clip region or not, but if this is the case then I think Juce should maintain it’s own RectangleList of clip rectangles (as it does in the SoftwareRenderer), because performancewise it is really crippling as it stands!
A small example to demonstrate:
[code]class testRedraw:public Component
{
public:
testRedraw(Rectangle pos, String name)
{
setBounds(pos);
setName(name);
setOpaque(true);
}
virtual void paint (Graphics& g)
{
Rectangle r = g.getClipBounds();
printf(“painting %s: (%d, %d, %d, %d)\n”, (const char*)getName().toUTF8(), r.getX(), r.getY(), r.getWidth(), r.getHeight() );
g.fillAll(Colour(0xFF000000 | rand()));
g.setColour(Colour(0xFF000000));
g.drawRect®;
}
} *test1, *test2, *test3;
class MyContentComponent : public Component, public Timer
{
public:
MyContentComponent()
{
setName(“MyContentComponent”);
setSize(500, 400);
addAndMakeVisible(test1 = new testRedraw(Rectangle(20,20,100,100), “A”));
addAndMakeVisible(test2 = new testRedraw(Rectangle(140,20,100,100), “B”));
addAndMakeVisible(test3 = new testRedraw(Rectangle(260,20,100,100), “C”));
startTimer(500);
}
virtual void timerCallback ()
{
test1->repaint();
test3->repaint();
}
virtual void paint (Graphics& g)
{
printf(“painting content component…!\n”);
g.fillAll(Colour(0xFFFFFFFF));
}
};[/code]
outputs:
painting content component...!
painting A: (0, 0, 100, 100)
painting B: (0, 0, 100, 100)
painting C: (0, 0, 100, 100)
painting content component...!
painting A: (0, 0, 100, 100)
painting B: (0, 0, 100, 100)
painting C: (0, 0, 100, 100)
etc…
Any ideas how this can be improved??