Repaint problem, is there a way to "delete" or hard reset a Graphic?

Hello everyone :slight_smile:

I have a strange Problem in my plugin. I have two images for my Background (same Image one of them is a copy of the other which is just desaturate.

So i have a simple bool variable, in my paint function i check this variable. If it’s true paint Image A if not paint Image B. Pretty simple.
So but now here is my problem.
If the value is changed, the background is not repainted complete. So behind my component’s (slider and buttons) i can see the other background everywhere else is the old image.

If i move the plugin window outside the monitor and back the Plugin is total repaint and looks good.

So this is what i tried:

  1. Detect that the value was toggled, if yes make a g.fillAll(Colours::white);
    Didn’t helped

  2. Detect that the value was toggled, if yes make a Clear Image and paint it first

     	g.setColour(Colours::yellow.withAlpha((uint8)128));
    
     	const int width = getWidth();
     	const int height = getHeight();
    
     	g.drawRect(0, 0, width, height);
    
     	Image image(Image::ARGB, 500 , 200, true);
     	image.clear(image.getBounds(), Colours::red.withAlpha(uint8(64)));
     	image.clear((image.getBounds() / 2).translated(30, 30));
    
     	g.setOpacity(1.0f);
     	g.drawImageAt(image, 10, 10);
    

Didn’t helped

  1. Detect that the value was toggled, if yes paint only the new background Image and after that return.

Everything was looking the same (behind the components i have the new image) the rest of the plugin has the old Image.

Has anyone a idea how i can make a “clear” repaint or something like that?

Thank you and best wishes
Martin

I think, maybe just call repaint() for the parent component should work. You can specify the area, that needs repainting to limit the CPU usage.

You just need a way of telling, when this is necessary. If you can’t tell, have a continuous repaint with a timer…

HTH

1 Like

The Background is painted in my AudioProcessorEditor, so it is the parent :slight_smile:
the paint function get’s called succesfully.

Or should i try to create a “background” class which i repaint manual?

Ok, but if it doesn’t paint the whole thing, just the sub components, but it does paint successfully when you move it outside the screen (i.e. the OS calls paint), then I would say, it is not called. There is no reason IMHO, why it should paint sometimes or sometimes something else…

I am afraid, there is another bug then in your code…

Maybe put a DBG in your paint() call and double check, if it is really really called…

No, that’s not needed…

1 Like

Aright i just added a repaint() in my PluginEditor::timercallback, now it’s painting perfectly.

actually this kills my cpu but now i get a full repaint and i can check how to get it perfomance. Thank you :wink:

Some more Questions to understand my Error:
My PluginProcessorEditor::paint function get called i think every 1-3 seconds (without a repaint call from my side).
Is that normal or i’m doing something wrong?

You can add the check in your timer callback as simple as

if (value != oldValue) {
    oldValue = value;
    repaint();  // maybe limit to repaint (Rectangle<int> ( 0, 0, 100, 100)); or whatever piece you want to repaint
}

I haven’t observed that, but it can also come from the OS or anything, that invalidates the view… another window moving over it, etc…
But every 1-3 seconds shouldn’t be much of a problem…?

1 Like

It isn’t a problem.

 if (value != oldValue) {
     oldValue = value;
     repaint();  // maybe limit to repaint (Rectangle<int> ( 0, 0, 100, 100)); or whatever piece you want to repaint
 }

Yes i do it like this.

Thanks for your fast help :slight_smile: