Hi,
I have the following UI layout:
- one rather large custom Component “Box1” displayed inside a Viewport;
- one small custom Component “Box2”, outside the Viewport, draggable around;
- a main window containing everything.
Main.cpp
MainComponent.h
MainComponent.cpp
Each component has its own paint()
method. For the large one (Box1) I would like to paint only the visible part by using the clipping bounds provided by the Graphics class, instead of a “raw” getLocalBounds()
. E.g.:
void Box1::paint(Graphics& g)
{
g.setColour(Colour(150, 150, 150));
g.fillRect(g.getClipBounds()); // g.fillRect(getLocalBounds()) would paint outside the viewport
g.setColour(Colour(200, 200, 200));
g.drawRect(g.getClipBounds(), 1);// g.drawRect(getLocalBounds(), 1) would paint outside the viewport
}
So far so good. However, as soon as I drag Box2 over Box1, Box1 gets visually damaged by Box2. The only way to repaint it properly is to move the viewport scrollbar a bit.
So I’m asking if there is a better/proper way to smart re-paint the component inside the viewport. I’m aware of Viewport::getViewArea()
: should I use it to somehow adjust the clipping bounds to my needs during Box1::paint()
?