Paint() question


#1

When I enter with the mouse on some component (f.i. TextButton) or leave this component with the mouse, the parent component (MainComponent) gets painted, too.

Is this normal?

Shouldn’t the TextButton only be redrawn? (plus ofcourse its background, which must have been precalculated ofcourse). This would involve some z-ordering ofcourse.


#2

Well yes, a button is semi-transparent, so its parents have to be redrawn before it can be painted. There’s no other way of doing it! Obviously the drawing is clipped to only the minimum area that it needs to cover.


#3

Well the background behind the control could be a bitmap that has been generated before and which is built of the underlying components that have been drawn previously.
This bitmap would have to be redrawn if components under our component would change.
This method would be faster than redrawing the clipped region, but would of course take more memory.

So paint (Graphics & g) gives the clipping region only? I didn’t know that, sorry. So, for instance, if a knob is repainted and the underlying region is
x1=100, y1=100, x2=200, y2=200
then only this region will be part of the graphics context Graphics &g and will need to be redrawn?


#4

No, letting components store some kind of ‘background’ of what’s underneath them is a crazy idea! If the thing underneath is very slow to draw, then you could make it cache itself using setBufferedToImage, but if it’s not, then there’s no disadvantage in just drawing it.

And yes, of course it’s all clipped to avoid drawing more than is actually necessary.


#5

Actually I thought some Operating Systems do it the way I thought :oops:


#6

I think old versions of windows might have done something that for dialog boxes, but it’s not a good design!


#7

Is your buffered Image code really taking into account the clipping region (in juce_Component.cpp: g->drawImageAt (bufferedImage_, 0, 0) ) ?


#8

Well yes, the blitting of that buffered image is clipped, same as any other operation that the Graphics class does. The buffered image itself is the same size as the component though.


#9

Ah ok, I understand. Cool.


#10