Hello,
there is method Component::repaint(int x, int y, int w, int h)
which allows to mark as “dirty” only selected area.
I wonder is there any way to get that area in Component::paint(Graphics& g)
?
For any help great thanks in advance.
Hello,
there is method Component::repaint(int x, int y, int w, int h)
which allows to mark as “dirty” only selected area.
I wonder is there any way to get that area in Component::paint(Graphics& g)
?
For any help great thanks in advance.
You can query the clip bounds of the Graphics context which is the area of the component will actually be redrawn:
https://docs.juce.com/master/classGraphics.html#a83d1918300e77b6f4302f880a1d10459
ImJimmi,
Thanks for your answer. But I’ve already tested getClipBounds()
and it doesn’t work as I expect.
My Component
has bounds Rectangle<int>(0, 0, 100, 100)
And I call repaint(0, 0, 10, 10)
Then in paint(Graphics& g)
I call:
g.fillAll(Colours::black);
g.setColour(Colours::red);
g.fillRect(g.getClipBounds());
So I expect there should be small square (10x10 pixels) drawn in the top left corner of my Component
, but it always filled fully with red colour.
Now I’ve just even tried that:
void MyComponent::paint(Graphics& g)
{
g.fillAll(Colours::black);
Rectangle<int> clipArea = g.getClipBounds();
if(clipArea.getWidth() <= 10)
{
g.setColour(Colours::red);
g.fillRect(clipArea);
}
}
Earlier code (in prevoius post) could cause situation where whole component was filled with red color because in some case was marked as whole dirty, and then repainting small red rectangle could be unvisible.
But now it should ensure that small red square is drawn only when marked as “dirty” area has size 10x10. But in that case the red square is never drawn.
So it looks like getClipBounds()
is not answer for my issue.
I’m a beginner at Juce, but have experience with c++, so bear this in mind when critiquing my proposal. Could you create a rectangle type variable as a class variable, then when repaint is called set the rectangle to the area you want. When the system eventually calls paint have it access that rectangle?
Matt
mengel136 thanks. Yes you are right, I could do as you proposed, but actually the problem is deeper. I am debuging my plugin. And I have problem because I set part of my plugin to repaint but always all other component are repainted too. And I try to figure it out why.
So create that question because I try to debug on what stage of repainting the selected area is lost and why.