Paint() - repaint() - inheritance doubt


#1

Hi everyone!.

I am creating a "chart" component to display signals - time - frecuency, etc.

So I created a component "chart". I draw on it some stuff as a window frame, x and y axis, labels and so on. At the same time it contains another component called "graph", in which i paint the graphic using the following at the paint():

Path line;

lines.addLineSegment(Line<float>(0, y, x, y), 20.0f);

And i create as many graphs components as signals I want to draw.

Well, I use a timer to update the graph every "x" ms, so I call, for example, from MainComponent :

Chart.graph1.repaint();

And it works, but this method also calls paint() parent method, so "chart" paint() method is redrawn all the time (frame, x y axis, labels, and so on). And not only this but graph2.paint() is also being called, so just calling Chart.graph1.repaint(); also repaints graph2.

Is it normal?or is there any way that parent paint methods are not called from children?I have tried to override the repaint() method (doing nothing) in parent class to see if this method was called instead of paint(), but both are executed.

I have seen in the demo, box2D, that there is an animation plus a listbox in the screen, and everytime the animation is refreshed, the listbox is repainted over and over again also, even without having had any change.

Is it so how it works by default, and the parent paint method is all the time being executed even without having any changes....??

I have read paintoverchildren method but I dont know how to use it :(

Is there any other way to redraw a graphic or whatever besides repaint()??I mean, can I write my own method to repaint??since it seems that "Graphics& g" is only to be used at paint() method,  I haven't been capable of declaring a Graphich component in my own function and use it as g.fillAll or fillpath or so.

 

I hope i have explained myself :D

Best regards and thanks in advance folks!!!

 

Carlosm


#2

When you call repaint(), the region of the component will be marked as "not up-to-date", if this component is not opaque and has as other underlying components, these components will be repainted too. If you repaint two different components, the regions will potentially merged to one big rectangle, if this rectangle intersects with a lot of other components, these will be repainted too. 

(btw for jules, I still think there is some kind of issue, when it comes to transformations, which triggers unnecessary repaints. http://www.juce.com/forum/topic/opaque-components-triggering-parents-component-paint ) 


#3

If I remember correctly, that is one reason why you always should set your component to "opaque" if possible.