Paint Performance when Multiple Components have the same Bounds

gui

#1

Does it impact paint performance if multiple components share the same position and size and all of them are setVisible(true) but of course only the topmost is seen on screen. Will JUCE only renderer the topmost component and not draw any other components at the same position and size that are placed behind it? or will the other components be rendered too but they are just not visible? so it would impact performance?

what i’m trying to do is fading between components.
lets say i got at least 2 components (componentA, componentB) both placed at 0,0,500,500. both visible but only the topmost component is seen.
now i got 2 buttons to switch which one should be visible on front.
i do the following if button A is clicked…

componentA->setAlpha(0.f);
componentA->toFront(true);
Desktop::getInstance().getAnimator().fadeIn(componentA.get(), 200);

and when i click on button B…

componentB->setAlpha(0.f);
componentB->toFront(true);
Desktop::getInstance().getAnimator().fadeIn(componentB.get(), 200);

The transition works fine and looks great! But if the components that are not seen are rendered too i have to change my code because i don’t want to waste performance…

Thanks in advance!


#2

add some DBG() statements to each component’s paint() method and check the console output.


#3

If a component has an alpha of 0 or you’ve called setVisible (false) on it then it won’t be drawn. But otherwise yes, all the bits of components that are in the repaint area and which aren’t behind an opaque component will need to be drawn each time.


#4

Also please check “Component::setBufferedToImage” - maybe it helps. It “makes the component use an internal buffer to optimise its redrawing.”


#5

Thanks a lot for all the replies. i already changed the code…
when clicked on button A i do…

Desktop::getInstance().getAnimator().cancelAnimation(componentA.get(), false);
componentA->toBack();
componentA->setAlpha(1.f);
Desktop::getInstance().getAnimator().fadeOut(componentB.get(), 200);
componentA->setVisible(true);
componentB->setVisible(false);

i still got the same fade effect but only one component is visible now…

thanks again