Reapaint() and overwriting


#1

In the following code faFreqAmpValues is an array containing values between 0 and 1, and fTimeXValue is initialised to 0.
My question is why does everything that was previously drawn seem to be erased every time the paint method is called, and is there a way to prevent this?

void DisplayComponent::paint (Graphics &g) { g.setColour(Colours::blue); for(int i=0;i<512;i++) { g.setOpacity(faFreqAmpValues[i]); g.drawHorizontalLine(i, fTimeXValue, fTimeXValue+1); } fTimeXValue+=1; }*/ }


#2

er… because that’s how all computer graphics has been done since the 1980s…

If you want to keep drawing onto the same image, you can just create your own Image object and draw onto it as much as you like.


#3

Ok thanks


#4

[quote=“jules”]

If you want to keep drawing onto the same image, you can just create your own Image object and draw onto it as much as you like.[/quote]

Does this mean that I create the Image object outside the paint method that covers a certain part of the component , and from there I can use the Graphics object in the paint method to draw lines on top of it that will remain?


#5

A Graphics object is already assigned to a target; if you use the one in the paint function, you are drawing to the component directly [which will always start blank].
You’d create your own image somewhere, and create your own Graphics object to draw to it. You would then draw that image onto the component using the Graphics instance provided to the paint callback.


#6

A belated thanks!